I am attempting to use the WinAPI function GUIDFromString()
but it requires some finagling to include it in my project.
According to the msdn documentation:
This function is not declared in a header or exported by name from a .dll file. It must be loaded from Shell32.dll as ordinal 703 for GUIDFromStringA and ordinal 704 for GUIDFromStringW.
It can also be accessed from Shlwapi.dll as ordinal 269 for GUIDFromStringA and ordinal 270 for GUIDFromStringW.
I have never loaded a DLL before so I am not sure what I should do and I am unsure if loading the DLL is enough, do I also have to include an 'ordinal' with the number 703? Would anyone be able to provide any advice on what I need to do to use this function and even an example?
My attempt below does not work(I am using VC++ 2010 Express):
#pragma comment(lib, "shell32.lib") // if I am including the dll do I need to include the lib aswell?
// I've heard that the dll location differs across versions of windows
// Does anyone know of a Cross-Windows-Version way to include Shell32.dll no matter where it is? Maybe use a keyword like "%SYSTEM%/Shell32.dll"
HINSTANCE shell32DLL = LoadLibary("C:/System/Shell32.dll");
// Now do I include 'Ordinal 703' as described in msdn? And how do I do that?
If you read the documentation for
GUIDFromString()
, it says:CLSIDFromString()
andIIDFromString()
are both exported by name from Ole32.dll, so you can use them like you would any other DLL function.With that said, if you still want to use
GUIDFromString()
then useLoadLibrary()
to load shell32.dll and then useGetProcAddress()
to access the function. MSDN documentation demonstrates how to do that. To load a function by ordinal, you can use theMAKEINTRESOURCE()
macro when callingGetProcAddress()
.So, for example:
Save the following lines as SHLWAPIX.DEF:
Save the following lines as SHLWAPIX.C:
Run
CL.EXE /LD /Zl SHLWAPIX.C /link /DEF:SHLWAPIX.DEF /NOENTRY
to create the import library SHLWAPIX.LIB, then delete SHLWAPIX.OBJ, SHLWAPIX.EXP and SHLWAPIX.DLLSave the following lines as SHLWAPIX.H:
Finally save the following lines as SHLWAPIX.C:
Finally run
CL.EXE /GS- SHLWAPIX.C
to create SHLWAPIX.EXE, then run the latter.This gives your an error "syntax error '('":
The proper version is: