digitalmars.D - Sharing the GetGUID() function for Windows I got working.
- David L. Davis <SpottedTiger yahoo.com> Jun 29 2004
This function can be very useful in so many different programs! :)) It took me a
little while to finally get this code to work, but that was half the fun of it.
Anywayz, I hope someone besides myself will find this code useful, as I know I
will in my future 'D' projects.
David
P.S. I sure hope someone can add 'HRESULT CoCreateGuid(GUID *rguid);' to com.d
in the near future...so I don't have to manually add it in myself for the newer
builds of 'D'. ;)
# // compiled with: C:\dmd>bin\dmd getguid.d ole32.lib uuid.lib -L/map
#
# /+
# ' NOTE - Before compiling, do the following:
# ' --------------------------------------------------------------
# ' In the "C:\dmd\src\phobos\std\c\windows\com.d" file, find
# ' line "int StringFromGUID2(GUID *rguid, LPOLESTR lpsz, int cbMax);"
# ' and add this line below it: "HRESULT CoCreateGuid(GUID *rguid);"
# +/
#
# import std.c.stdio;
# import std.c.windows.com;
#
# extern( Windows )
# {
# long CoCreateGuid( GUID *pGUID );
# int StringFromGUID2( GUID *rguid, LPOLESTR lpsz, int cbMax );
# }
#
# int main()
# {
# printf( "New GUID: %.*s\n", CreateGUID() );
#
# return 0;
# }
#
# char[] CreateGUID()
# {
# GUID udtGUID;
# wchar[ 39 ] sGUID = '\0';
# long lResult;
# char[] sGUID2 = "";
#
# lResult = CoCreateGuid( &udtGUID );
#
# if ( lResult < 0 )
# return "";
# else
# {
# StringFromGUID2( &udtGUID, sGUID, 39 );
# }
#
# for ( int ix = 0; ix < sGUID.length - 1; ix++ )
# {
# // printf( "sGUID[ %d ] = %c\n", ix, sGUID[ ix ] );
# sGUID2 ~= sGUID[ ix ];
# }
#
# return sGUID2;
#
# } // end char[] CreateGUID()
-------------------------------------------------------------------
"Dare to reach for the Stars...Dare to Dream, Build, and Achieve!"
Jun 29 2004








David L. Davis <SpottedTiger yahoo.com>