if you use netmaestros first example, you have to change the code a little bit. Change also the procedure return type from .l to .i, its a pointer.
Code: Select all
; ASCII only for this version...
Procedure.i ansi2bstr(ansi.s)
Size.l=MultiByteToWideChar_(#CP_ACP,0,ansi,-1,0,0)
Dim unicode.w(Size)
MultiByteToWideChar_(#CP_ACP, 0, ansi, Len(ansi), unicode(), Size)
ProcedureReturn SysAllocString_(@unicode())
EndProcedure
Define CLSID_ShellLink.CLSID, shlCLSID.s, hRes.l, *bStr
shlCLSID = "{00021401-0000-0000-C000-000000000046}"
*bStr = ansi2bstr(shlCLSID)
hRes = CLSIDFromString_(*bStr , @CLSID_ShellLink)
Select hRes
Case #NOERROR
Debug "Success"
Case #CO_E_CLASSSTRING
Debug "The class string was improperly formatted."
Case #REGDB_E_CLASSNOTREG
Debug "The CLSID corresponding to the class string was not found in the registry."
Case #REGDB_E_READREGDB
Debug "The registry could not be opened for reading."
Default
Debug hRes
EndSelect
SysFreeString_(*bStr)
If I often call such procedures like
ansi2bstr, i use the following code:
Code: Select all
; ASCII only for this version...
Procedure.i ansi2bstr(ansi.s)
Static bStr.i
SysFreeString_(bStr)
If ansi = ""
ProcedureReturn
EndIf
Size.l=MultiByteToWideChar_(#CP_ACP,0,ansi,-1,0,0)
Dim unicode.w(Size)
MultiByteToWideChar_(#CP_ACP, 0, ansi, Len(ansi), unicode(), Size)
bStr = SysAllocString_(@unicode())
ProcedureReturn bStr
EndProcedure
Define CLSID_ShellLink.CLSID, shlCLSID.s, hRes.l
shlCLSID = "{00021401-0000-0000-C000-000000000046}"
hRes = CLSIDFromString_(ansi2bstr(shlCLSID) , @CLSID_ShellLink)
Select hRes
Case #NOERROR
Debug "Success"
Case #CO_E_CLASSSTRING
Debug "The class string was improperly formatted."
Case #REGDB_E_CLASSNOTREG
Debug "The CLSID corresponding to the class string was not found in the registry."
Case #REGDB_E_READREGDB
Debug "The registry could not be opened for reading."
Default
Debug hRes
EndSelect
With this code it's secured, that all the running time is only one bString stored by this procedure. At the end of you program you call one time: