` Creating a GUID (Jim Kane) - Icetips Article
Icetips - Templates, Tools & Utilities for Clarion Developers

Templates, Tools and Utilities
for Clarion Developers

Icetips Article

Back to article list   Search Articles     Add Comment     Printer friendly     Direct link  

Windows API: Creating a GUID
2003-04-29 -- Jim Kane
 
Newsgroups: comp.lang.clarion Notice in the c prototype ** ? That means pointer to a pointer. You need to do one more copy. What you are getting back is a pointer to the string. My code uses call by address since the dlls involved are not found on all os but you can use a lib if all your customers will have nt or higher if SELF.CallDllCl.Init(Dllname,SELF.Debug) SELF.TakeError('RpcRt4.dll not found','CreateGuid') do procret end SELF.calldllcl.setprocfailcode(1) procresult = SELF.calldllcl.call('UuidCreate',plpGuid) if procresult<>0 If procresult = 1824 then SELF.TakeError('No NIC in this Machine','CreateGuid') elsif res = 1739 SELF.TakeError('Unable to get NIC Address','CreateGuid') else SELF.TakeError('UUIDCreate Failed','CreateGuid') end do procret End if ~omitted(3) then !Convert to a string ProcResult=SELF.calldllcl.call('UuidToStringA', plpguid ,address(UuidStrPtr)) If ProcResult<>0 or ~uuidstrptr then SELF.TakeError('Uuidstr fail','CreateGuid') do procret End !Copy string from RPC Owned Memory to CW memory if size(pGuidStr)< lstrlen(uuidstrptr)+1 then SELF.TakeError('Guid string is too short: Required='&lstrlen(uuidstrptr) & ' provided='&size(pGuidStr),'CreateGuid') do procret else lstrcpy(address(tempcStr),UuidStrPtr) pGuidStr=tempcstr res=return:benign end end do procret procret routine !free the RPC Memory, if any was obtained if uuidstrptr then SELF.calldllcl.call('RpcStringFreeA', address(UuidStrPtr)) end SELF.CallDllCl.kill() return res Notice the extra lstrcpy and finally the call to rpcstringfreeA Jim Kane "Charles Ballard" wrote in message news:3eaebf1c$1@news.softvelocity.com... > I believe I have successfully used CoCreateGuid to create the uuid I need, > but I'm having trouble getting the UuidToString API to work: > > I have used LibMaker to generate a .lib for rpcrt4.dll. I have prototyped > the functions as such: > > !Atomic Equates > DWORD EQUATE(LONG) !4-byte signed > WORD EQUATE(USHORT) !2-byte unsigned > !Compound Equates > GUID GROUP,TYPE > Data1 DWORD > Data2 WORD > Data3 WORD > Data4 STRING(8) > END > > MODULE('Rpcrt4.DLL') > UuidToString(*GUID,*CSTRING),UNSIGNED,PASCAL,RAW,NAME('UuidToStringA') > END > MODULE('Ole32.DLL') > CoCreateGuid(*GUID),HRESULT,PASCAL,RAW > END > > And I'm calling them like this: > > DATA > loc:guid GROUP(GUID). > loc:guidStr cstring(27) > CODE > clear(loc:guid) > e#=CoCreateGuid(loc:guid) > !I seem to have valid data in the group at this point > e#=UuidToString(loc:guid,loc:guidStr) > !But loc:guidStr gives me garbage here > > I get no compile or link errors, but no useable uuid, either. > > The MSDN definition of the UuidToString function is this: > > RPC_STATUS RPC_ENTRY UuidToString( > UUID *Uuid, > unsigned char **StringUuid > ); > Parameters > Uuid > Pointer to a binary UUID. > StringUuid > Pointer to a pointer to the string into which the UUID specified in the > Uuid parameter shall be placed. > I'm pretty sure I'm using it incorrectly. > Any ideas? > Thanks, > Charles > >


Today is November 21, 2024, 3:56 am
This article has been viewed 35399 times.
Google search has resulted in 367 hits on this article since January 25, 2004.



Back to article list   Search Articles   Add Comment   Printer friendly

Login

User Name:

Password: