sieukrem / jn-npp-plugin

Plugin for Notepad++ allowing you to automate some tasks using JavaScript
https://github.com/sieukrem/jn-npp-plugin/wiki
110 stars 24 forks source link

GetModuleHandleW #35

Closed lollita closed 8 years ago

lollita commented 8 years ago

why:

require(require.currentDir+"\lib\Library.js"); var Kernel32 = new Library("Kernel32.dll"); Kernel32.Define("GetModuleHandleW", "LPCTSTR"); hModule=Kernel32.GetModuleHandleW("hhctrl.ocx") alert(hModule);

return 0? no problem with f.e.: hModule=Kernel32.GetModuleHandleW("Kernel32.dll")

sieukrem commented 8 years ago

what about x64 and x86?

Try to get last error code GetLastError

sieukrem commented 8 years ago

You have to load a module using LoadLibrary before you call GetModuleHandle. Following example works as expected.

require("/lib/Library.js");

var Kernel32 = new Library("Kernel32.dll");
var hhctrl = new Library("hhctrl.ocx");

Kernel32.Define("GetModuleHandleW", "LPCTSTR");

hModule=Kernel32.GetModuleHandleW("hhctrl.ocx")

alert(hModule);