April 25, 2024, 04:00:18 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Unresolved external problem again

Started by Andy, September 08, 2017, 07:37:45 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

September 08, 2017, 07:37:45 AM Last Edit: September 08, 2017, 07:39:28 AM by Andy
I came across this function yesterday - RegCopyTreeA - it is a built in function of advapi32.dll, unfortunately it is one of two functions not included in the windows.inc file.

It allows you to copy a registry key to a new key - which is very handy for me - but I keep getting an unresolved external message at compile time.

Linking...
IWBasic Linker v1.11 Copyright © 2011 Ionic Wind Software
Unresolved external __imp_RegCopyTreeA
Error: c:\users\andy\appdata\local\ionicwind\iwbasic3\examples\ren1.o - Unresolved extern __imp_RegCopyTreeA
Error(s) in linking c:\users\andy\appdata\local\ionicwind\iwbasic3\examples\ren1.exe

Now I've checked the dll file and RegCopytreeA does indeed exist, so how do I declare it?

declare "advapi32.dll", RegCopyTreeA(hkey as Uint, Dest as String,hkeyD as Uint),int  ???

If I can get this working it will same me so much time...

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

Brian

Andy,

I found a VBA example, and it translated like this:

DECLARE IMPORT,RegCopyTreeA(hKeySrc:INT,lpSubKey:STRING,hKeyDest:INT),INT

Brian

fasecero

You can do this by calling the function dynamically. Use Brian's statement as template and call LoadLibrary + GetProcAddress. You can rely on the functions where we convert UINT64 to STRING and vice versa.

Andy

Thanks guys,

I took a little time to study what was being suggested and for the first time ever I understand how you load up a dll and use one of it's functions.

I can now use it to copy a key.

Just on the subject of dll's, the other function is NtRenameKey.

Here is a link to msdn:
https://msdn.microsoft.com/en-us/library/cc512138(v=vs.85).aspx

How do I declare this in IWB as the new name has to be UNICODE?

And how do I pass it to a sub directory?

Thanks again, It's a big help!!!
 
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

fasecero

Nice. WSTRING will probably work fine. If not, you have to declare it as POINTER instead.

Andy

Why or why did MS have to make this a WString!   :-X

I've tried for hours now but the program crashes, I've tried wstrings and pointers, just can't get it to work.

The ntdll.dll loads okay, so does the function NtRenamekey.

The declare is:

DECLARE CDECL NtRenameKey(hKey as uint,NewKeyName as WSTRING),uINT

and the line which is causing the crash is:

RegRenameResult = !<NtRenameKey>proc(ret,L"HKEY_CURRENT_USER\\Software\\Test6")

It's not a complete disaster, I could just just the copy key function and then delete the original key - but I just wonder if the rename key function will be quicker - and why I can't get it to work.


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

fasecero

Try using single backslash and removing CDECL.

Andy

Removing CDECL worked for the copy key function!

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

Andy

September 11, 2017, 05:17:05 AM #8 Last Edit: September 11, 2017, 05:24:29 AM by Andy
Couldn't get the rename key function to work, so I'm copying the key first, then deleting the original as an alternative.
Also, the rename key function is only available for Win Vista and later - and I want our XP friends to be able to use all my new library functions.

I found an error in the old RegdeleteKey function.  It seems that if a key has sub-keys then it will fail.

But I've got the RegDeleteTreeA function working as well, this deletes all Sub keys of a specified key.

So I will amend the delete key function in the new library to check for Sub keys first, if it has some, I will use the delete tree function to remove them, and finally delete the key.

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