What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [?] GetProcAddress and LoadLibraryW

[?] GetProcAddress and LoadLibraryW
Author: Message:
SmokingCookie
Senior Member
****

Avatar

Posts: 815
Reputation: 15
30 / Male / Flag
Joined: Jul 2007
O.P. [?] GetProcAddress and LoadLibraryW
Wow I've been away for a LOOOOOOOONG time man :|

Anyways, I'm having trouble getting GetProcAddress to do what I want. I've managed to have it return a valid (and the right) address value for the ordinal value associated with LoadLibraryW, but it won't work for the string "LoadLibraryW". My code:

Javascript code:
var GetModuleHandle = function(ModuleName) {
    Print("Getting module handle for " + ModuleName);
    return Interop.Call("Kernel32.dll","GetModuleHandleW",ModuleName);
}
 
var GetProcAddress = function(hModule,ProcName) {
    Print("Getting procedure address for " + ProcName);
    return Interop.Call("Kernel32.dll","GetProcAddress",hModule,ProcName);
}


This code does return a valid hModule, but the procedure address is zero/NULL for the "LoadLibraryW" string. I've checked the ordinal value on Vista x64 SP2; it's not the same as the XP one. That's why I want this to work with the procedure name, rather than its ordinal value.

I've read the remarks in the MSDN article on GetProcAddress - that's why I came up with the ordinal value thing - but I can't figure out what I'm doing wrong. So, could anyone please help me with this issue?

FTR, I'm on Windows XP x86 SP 3.

This post was edited on 04-09-2011 at 07:18 PM by SmokingCookie.
04-09-2011 07:17 PM
Profile PM Find Quote Report
Eljay
Elite Member
*****

Avatar
:O

Posts: 2949
Reputation: 77
– / Male / –
Joined: May 2004
RE: [?] GetProcAddress and LoadLibraryW
GetProcAddress doesn't take a unicode string :P

Javascript code:
function Print(s){Debug.Trace(s);}
 
var GetModuleHandle = function(ModuleName) {
    Print("Getting module handle for " + ModuleName);
    return Interop.Call("Kernel32.dll","GetModuleHandleW",ModuleName);
}
 
var GetProcAddress = function(hModule,ProcName) {
    Print("Getting procedure address for " + ProcName);
    var DataBloc = Interop.Allocate(ProcName.length + 1);
    DataBloc.WriteString(0, ProcName, false);
    return Interop.Call("Kernel32.dll","GetProcAddress",hModule,DataBloc);
}
 
var a = GetModuleHandle("kernel32.dll");
Debug.Trace(a);
var b = GetProcAddress(a, "LoadLibraryW");
Debug.Trace(b);

04-09-2011 07:56 PM
Profile PM Find Quote Report
SmokingCookie
Senior Member
****

Avatar

Posts: 815
Reputation: 15
30 / Male / Flag
Joined: Jul 2007
O.P. RE: [?] GetProcAddress and LoadLibraryW
Got it working, thanks :D
04-10-2011 08:25 AM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On