Page 1 of 1

VarCmp invalid memory access (VARIANT)

Posted: Mon Feb 03, 2020 11:09 am
by Rinzwind
This c code (known to be working)

Code: Select all

	VARIANT a, b;
	a.vt = VT_BSTR;
	b.vt = VT_BSTR;
	a.bstrVal = SysAllocString(L"a");
	b.bstrVal = SysAllocString(L"b");
	HRESULT c = VarCmp(&a, &b, LOCALE_USER_DEFAULT, NORM_IGNORECASE);
Translated into PB (had to mention a full lib path because the one with PB gives linker error?)

Code: Select all

  Import "C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17763.0\um\x64\OleAut32.lib"
    VarCmp(*lvar.VARIANT, *rvar.VARIANT, lcid.l, dwFlags.l)
  EndImport 
  
  
  Define  a.VARIANT, b.VARIANT
  a\vt = #VT_BSTR
  a\bstrVal = SysAllocString_("a")
  b\vt = #VT_BSTR
  b\bstrVal = SysAllocString_("b")
  
  Debug VarCmp(a, b, #LOCALE_USER_DEFAULT, #NORM_IGNORECASE)
Gives Invalid memory access. (read error at address...)

Whatsup?

Re: VarCmp invalid memory access (VARIANT)

Posted: Mon Feb 03, 2020 11:16 am
by Rinzwind
Interestingly, the 32 bit one in 32 bit PB does work...
Crying

Code: Select all

  Import "C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17763.0\um\x86\OleAut32.lib"
    VarCmp(*lvar.VARIANT, *rvar.VARIANT, lcid.l, dwFlags.l)
  EndImport 
  
  
  Define  a.VARIANT, b.VARIANT
  a\vt = #VT_BSTR
  a\bstrVal = SysAllocString_("a")
  b\vt = #VT_BSTR
  b\bstrVal = SysAllocString_("b")
  
  Debug VarCmp(a, b, #LOCALE_USER_DEFAULT, #NORM_IGNORECASE)
  
  
So why 64 bit gives problems here...

tried also

Code: Select all

  Import "C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17763.0\um\x64\OleAut32.lib"
    VarCmp(*lvar.p-variant, *rvar.p-variant, lcid.l, dwFlags.l)
  EndImport 
  
  
  Define  a.VARIANT, b.VARIANT
  a\vt = #VT_BSTR
  a\bstrVal = SysAllocString_("a")
  b\vt = #VT_BSTR
  b\bstrVal = SysAllocString_("b")
  
  Debug VarCmp(a, b, #LOCALE_USER_DEFAULT, #NORM_IGNORECASE)
  

Re: VarCmp invalid memory access (VARIANT)

Posted: Mon Feb 03, 2020 11:46 am
by fryquez
copy "C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17763.0\um\x64\OleAut32.lib" to "PureLibraries\Windows\Libraries\" overwriting the old one.

Re: VarCmp invalid memory access (VARIANT)

Posted: Mon Feb 03, 2020 11:47 am
by Rinzwind
Well anyway, the alternative with openlibrary does seem to work... Just don't know why

Prototype VarCmp(*lvar.VARIANT, *rvar.VARIANT, lcid.l, dwFlags.l)
Global OleAut32 = OpenLibrary(#PB_Any, "OleAut32.dll")
Global VarCmp.VarCmp = GetFunction(OleAut32, "VarCmp")

Re: VarCmp invalid memory access (VARIANT)

Posted: Mon Feb 03, 2020 11:51 am
by Rinzwind
Ah copying to PB folder did also fix it indeed. Not sure why the full path is PARTLY ignored then... It does compile, just crashes at runtime... but does work in 32 bit PB...

Re: VarCmp invalid memory access (VARIANT)

Posted: Mon Feb 03, 2020 1:03 pm
by Fred
May be the 2 .lib were linked hence an incompatibility

Re: VarCmp invalid memory access (VARIANT)

Posted: Mon Feb 03, 2020 4:55 pm
by mk-soft
Use library from Pelles C.
I haven't tested it, but had already used the library of Pelles C for OleAut32.

https://www.pellesc.de