April 26, 2024, 02:06:37 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Unhandled win32 exception

Started by Andy, September 10, 2017, 01:44:18 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

September 10, 2017, 01:44:18 AM Last Edit: September 10, 2017, 01:50:05 AM by Andy
This one has me even more puzzled.

When I use my new RegCopyKey function in a console - it works.

Like this:
print RegCopyKey("HKEY_CURRENT_USER\\Software\\Test","HKEY_CURRENT_USER\\Software\\Test5")


When I use my new RegCopyKey function in a window handler - it doesn't.

I used Visual Studio to debug the program and it's telling me it's an Access Violation - which is nonsense to me as the key I'm copying is a key I made, and I have full access rights to it.

I've tried it on Anne's laptop (Win7 32 bit) and I get the same problem.
My PC is Win10 32 bit.

I've tried the usual TRY / ENDTRY / CATCH - but that doesn't catch it.
I've tried Debug build mode - but that doesn't catch it either.

This is the code for RegCopyKey - the line causing the problem is:
RegCopyResult = !<RegCopyTreeA>proc(ret,"",ret2)

global Sub RegCopyKey(Key as String,ToKey as string),int
    string rfd,kyd,hyD
    UInt ret,ret2,ret3,typ,retd,tmpd
string rf,rf2,ky,ky3
UInt root
int retval,tmp,ln,RegCopyResult

print Key
print ToKey
print


    RegCreateKey(ToKey)

    'Source key 
    rf=left$(Key,instr(Key,"\\")-1)
    ky=right$(Key,len(Key)-1-len(rf))
    if RegOpenKeyExA(GetRoot(Key),ky,0,@KEY_ALL_ACCESS,ret) = 0
    else
       Return -1 
    endif

    'Destination key
    rf=left$(ToKey,instr(ToKey,"\\")-1)
    ky=right$(ToKey,len(ToKey)-1-len(rf))
    if RegOpenKeyExA(GetRoot(ToKey),ky,0,@KEY_ALL_ACCESS,ret2) = 0
    else
       Return -1 
    endif

UINT hInst=LoadLibrary("advapi32.dll")

IF hInst THEN
UINT proc = GetProcAddress(hInst,"RegCopyTreeA")
IF proc THEN
print "copying...."
          try
    RegCopyResult = !<RegCopyTreeA>proc(ret,"",ret2)
          endtry
catch
             print "exception code: 0x" ', hex$(GetExceptionCode())
          endcatch

print " copy done!"
ENDIF

       RegCloseKey(ret)
       RegCloseKey(ret2)
       FreeLibrary(hInst)
    endif

   return RegCopyResult
EndSub



How can I get around this?
And why is it happening?
???

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

fasecero

Same as before, probably. Advapi32 uses the STDCALL calling convention, I think  ???. So remove CDECL.