forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


API Help: Calling CoCreateGuid in OLE32.DLL ???

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Advanced Help for VDS 5 & Up
View previous topic :: View next topic  
Author Message
henrywood
Contributor
Contributor


Joined: 21 Sep 2004
Posts: 66
Location: Copenhagen, Denmark

PostPosted: Wed Jul 06, 2005 2:41 am    Post subject: API Help: Calling CoCreateGuid in OLE32.DLL ??? Reply with quote

Hi guys !

I am trying to figure out how to call the API function CoCreate in order to get an GUID

Can anyone help ?

# VB Code
#Type GUID
# Data1 As Long
# Data2 As Integer
# Data3 As Integer
# Data4(7) As Byte
#End Type
#
#Declare Function CoCreateGuid Lib "OLE32.DLL" (pGuid As GUID) As Long

#Private Const S_OK = 0 ' return value from CoCreateGuid

# VDS Code
LOADLIB OLE32.DLL
# Here we should create the %%PGUID Struct or - but how ???

%%GUID = @lib(ole32,CoCreateGuid,STR:,%%PGUID)
FREELIB OLE32.DLL
info %%GUID
Back to top
View user's profile Send private message Send e-mail
LiquidCode
Moderator Team


Joined: 05 Dec 2000
Posts: 1753
Location: Space and Time

PostPosted: Thu Jul 07, 2005 1:50 am    Post subject: Reply with quote

Well, I don't know that, but if you need a GUID, this DSU can make them.

http://www.vdsworld.com/search.php?keywords=GUID&match_type=0&sid=6edb160244aa6a65df718fb593b40b87

_________________
Chris
Http://theblindhouse.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
henrywood
Contributor
Contributor


Joined: 21 Sep 2004
Posts: 66
Location: Copenhagen, Denmark

PostPosted: Thu Jul 07, 2005 9:30 pm    Post subject: Thanks ! Reply with quote

Hi Liquid !

Well, my original thought was to use that DSU. However, I need to be absolutely sure that the GUID is infact 100% unique across multiple machines, since I use the GUID as a primary key in a database.

I ended up solving it by combining the GUID and MAC address (without -) to insure that at least the MAC part was unique thus making the complete GUID unique.

But thanks for your suggestion anyway



Henrik
Back to top
View user's profile Send private message Send e-mail
Garrett
Moderator Team


Joined: 04 Oct 2001
Posts: 2149
Location: A House

PostPosted: Thu Jul 07, 2005 10:37 pm    Post subject: Reply with quote

Good workaround Henry Smile

-Garrett
Back to top
View user's profile Send private message
LiquidCode
Moderator Team


Joined: 05 Dec 2000
Posts: 1753
Location: Space and Time

PostPosted: Thu Jul 07, 2005 10:45 pm    Post subject: Reply with quote

Indeed, Nice. I might have to employ that method as well.
_________________
Chris
Http://theblindhouse.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
vdsalchemist
Admin Team


Joined: 23 Oct 2001
Posts: 1448
Location: Florida, USA

PostPosted: Fri Sep 02, 2005 12:38 am    Post subject: Re: API Help: Calling CoCreateGuid in OLE32.DLL ??? Reply with quote

henrywood wrote:
Hi guys !

I am trying to figure out how to call the API function CoCreate in order to get an GUID

Can anyone help ?

# VB Code
#Type GUID
# Data1 As Long
# Data2 As Integer
# Data3 As Integer
# Data4(7) As Byte
#End Type
#
#Declare Function CoCreateGuid Lib "OLE32.DLL" (pGuid As GUID) As Long

#Private Const S_OK = 0 ' return value from CoCreateGuid

# VDS Code
LOADLIB OLE32.DLL
# Here we should create the %%PGUID Struct or - but how ???

%%GUID = @lib(ole32,CoCreateGuid,STR:,%%PGUID)
FREELIB OLE32.DLL
info %%GUID


henrywood,
Have you tried the following...
Code:
# VDS Code
#Define Function,WideChartoString
LOADLIB OLE32.DLL
# Here we should create the %%PGUID Struct or - but how ???
%A = @fill(16,,Z)
%%Ret = @lib(ole32,CoCreateGuid,DWORD:,@Addr("%A"))
If @Null(%%Ret)
  %B = @fill(256,@chr(32))
  %%Ret = @lib(ole32,StringFromGUID2,INT:,@Addr("%A"),@Addr("%B"),256)
  info @WideChartoString(%B,256)@CR()
End
FREELIB OLE32.DLL
Exit

:WideChartoString
  Rem This sub routine attempts to convert a Wide Character string to a
  rem ASCII character string.
  rem Wide Charater strings are used for non ASCII codepages
  rem
  %Q = %1
  rem Add the number of charaters to traverse
  %%cnt2 = %2
  %%MyString =
  rem Set the starting character
  %%cnt = 1
  rem Loop through the charaters and only return the ASCII charaters
  repeat
    Rem Read each byte and convert it to a character
      %S = @SubStr(%Q,%%cnt)
      if %S
       %%MyString = %%MyString%S
      End
      %%cnt = @Succ(%%cnt)     
  Until @Greater(%%cnt,%%cnt2)
  Rem Return our string
Exit %%MyString

_________________
Home of

Give VDS a new purpose!
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
henrywood
Contributor
Contributor


Joined: 21 Sep 2004
Posts: 66
Location: Copenhagen, Denmark

PostPosted: Fri Sep 02, 2005 11:27 am    Post subject: Thanks ! Reply with quote

Hi dragonspere,

It works nicely !


Thank you Smile
Back to top
View user's profile Send private message Send e-mail
vdsalchemist
Admin Team


Joined: 23 Oct 2001
Posts: 1448
Location: Florida, USA

PostPosted: Fri Sep 02, 2005 1:59 pm    Post subject: Reply with quote

Henry,
Just to let you know that there is a small issue with the WideChartoString which I have not fixed yet. If the Wide Character String or OLESTRING has some other character than @chr(0) in it then VDS will capture those characters. Although this should not effect this example since there will always be @chr(0) between the characters of a GUID string. The OS only uses characters found in Hex numbers when creating a GUID. There is another way to do this so take a look at the code below. This is the same code as before but now it shows both ways to do this.

Code:

# VDS Code
#Define Function,WideChartoString
LOADLIB OLE32.DLL
# Here we should create the %%PGUID Struct or - but how ???
%A = @fill(16,,Z)
%%Ret = @lib(ole32,CoCreateGuid,DWORD:,@Addr("%A"))
If @Null(%%Ret)
  # The hard way but no issues with
  # getting garbage characters in the string.
  %%Data1 = @hex(@Val(@SubStr(%A,3,4)),4)@hex(@Val(@SubStr(%A,1,2)),4)
  %%Data2 = @hex(@Val(@SubStr(%A,5,6)),4)-@hex(@Val(@SubStr(%A,7,Cool),4)
  %%Data3 = @hex(@Val(@SubStr(%A,9)),2)@hex(@Val(@SubStr(%A,10)),2)
  %%Data4 = @hex(@Val(@SubStr(%A,11)),2)@hex(@Val(@SubStr(%A,12)),2)@hex(@Val(@SubStr(%A,13)),2)@hex(@Val(@SubStr(%A,14)),2)@hex(@Val(@SubStr(%A,15)),2)@hex(@Val(@SubStr(%A,16)),2)
  %%GUID = {%%Data1-%%Data2-%%Data3-%%Data4}
  Info %%GUID@CR()
  # The easy way but potential of getting garbage
  # characters in the string due to the WideChartoString function.
  %B = @fill(256,@chr(32))
  %%Ret = @lib(ole32,StringFromGUID2,INT:,@Addr("%A"),@Addr("%B"),256)
  info @WideChartoString(%B,256)@CR()
End
FREELIB OLE32.DLL
Exit

:WideChartoString
  Rem This sub routine attempts to convert a Wide Character string to a
  rem ASCII character string.
  rem Wide Charater strings are used for non ASCII codepages
  rem
  %Q = %1
  rem Add the number of charaters to traverse
  %%cnt2 = %2
  %%MyString =
  rem Set the starting character
  %%cnt = 1
  rem Loop through the charaters and only return the ASCII charaters
  repeat
    Rem Read each byte and convert it to a character
      %S = @SubStr(%Q,%%cnt)
      if %S
       %%MyString = %%MyString%S
      End
      %%cnt = @Succ(%%cnt)     
  Until @Greater(%%cnt,%%cnt2)
  Rem Return our string
Exit %%MyString


_________________
Home of

Give VDS a new purpose!
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
henrywood
Contributor
Contributor


Joined: 21 Sep 2004
Posts: 66
Location: Copenhagen, Denmark

PostPosted: Mon Sep 05, 2005 2:58 pm    Post subject: Re: Thanks Reply with quote

Hi dragonsphere !


I will try the new approach then. Thanks

I was wondering if you would be interested in compiling a small DLL for me (I have a C++ class that needs to be wrapped in a VDS DLL)

Please see
http://www.vdsworld.com/forum/viewtopic.php?t=3554


Henrik
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Advanced Help for VDS 5 & Up All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group