| View previous topic :: View next topic |
| Author |
Message |
henrywood Contributor

Joined: 21 Sep 2004 Posts: 66 Location: Copenhagen, Denmark
|
Posted: Wed Jul 06, 2005 2:41 am Post subject: API Help: Calling CoCreateGuid in OLE32.DLL ??? |
|
|
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 |
|
 |
LiquidCode Moderator Team
Joined: 05 Dec 2000 Posts: 1753 Location: Space and Time
|
|
| Back to top |
|
 |
henrywood Contributor

Joined: 21 Sep 2004 Posts: 66 Location: Copenhagen, Denmark
|
Posted: Thu Jul 07, 2005 9:30 pm Post subject: Thanks ! |
|
|
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 |
|
 |
Garrett Moderator Team
Joined: 04 Oct 2001 Posts: 2149 Location: A House
|
Posted: Thu Jul 07, 2005 10:37 pm Post subject: |
|
|
Good workaround Henry
-Garrett |
|
| Back to top |
|
 |
LiquidCode Moderator Team
Joined: 05 Dec 2000 Posts: 1753 Location: Space and Time
|
Posted: Thu Jul 07, 2005 10:45 pm Post subject: |
|
|
Indeed, Nice. I might have to employ that method as well. _________________ Chris
Http://theblindhouse.com |
|
| Back to top |
|
 |
vdsalchemist Admin Team

Joined: 23 Oct 2001 Posts: 1448 Location: Florida, USA
|
Posted: Fri Sep 02, 2005 12:38 am Post subject: Re: API Help: Calling CoCreateGuid in OLE32.DLL ??? |
|
|
| 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 |
|
 |
henrywood Contributor

Joined: 21 Sep 2004 Posts: 66 Location: Copenhagen, Denmark
|
Posted: Fri Sep 02, 2005 11:27 am Post subject: Thanks ! |
|
|
Hi dragonspere,
It works nicely !
Thank you  |
|
| Back to top |
|
 |
vdsalchemist Admin Team

Joined: 23 Oct 2001 Posts: 1448 Location: Florida, USA
|
Posted: Fri Sep 02, 2005 1:59 pm Post subject: |
|
|
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, ),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 |
|
 |
henrywood Contributor

Joined: 21 Sep 2004 Posts: 66 Location: Copenhagen, Denmark
|
Posted: Mon Sep 05, 2005 2:58 pm Post subject: Re: Thanks |
|
|
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 |
|
 |
|
|
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
|
|