VarCmp invalid memory access (VARIANT)

Windows specific forum
Rinzwind
Enthusiast
Enthusiast
Posts: 638
Joined: Wed Mar 11, 2009 4:06 pm
Location: NL

VarCmp invalid memory access (VARIANT)

Post 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?
Rinzwind
Enthusiast
Enthusiast
Posts: 638
Joined: Wed Mar 11, 2009 4:06 pm
Location: NL

Re: VarCmp invalid memory access (VARIANT)

Post 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)
  
fryquez
Enthusiast
Enthusiast
Posts: 367
Joined: Mon Dec 21, 2015 8:12 pm

Re: VarCmp invalid memory access (VARIANT)

Post 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.
Rinzwind
Enthusiast
Enthusiast
Posts: 638
Joined: Wed Mar 11, 2009 4:06 pm
Location: NL

Re: VarCmp invalid memory access (VARIANT)

Post 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")
Rinzwind
Enthusiast
Enthusiast
Posts: 638
Joined: Wed Mar 11, 2009 4:06 pm
Location: NL

Re: VarCmp invalid memory access (VARIANT)

Post 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...
Fred
Administrator
Administrator
Posts: 16681
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: VarCmp invalid memory access (VARIANT)

Post by Fred »

May be the 2 .lib were linked hence an incompatibility
User avatar
mk-soft
Always Here
Always Here
Posts: 5393
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: VarCmp invalid memory access (VARIANT)

Post 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
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply