Sign in to follow this  
cartographer

[.net] Exception while loading unmanaged Dll into C# Code

Recommended Posts

Hi all i have developed a dll in VC++7.0 and want to use it in C# code but i got exception: " Unable to load DLL 'HookLib.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E) " my Dll code is: ////////////////////////"HookLib.cpp" #include "stdafx.h" extern HINSTANCE g_appInstance; BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD ul_reason_for_call, LPVOID lpReserved) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: // // Capture the application instance of this module to pass to // hook initialization. // if (g_appInstance == NULL) { g_appInstance = hinstDLL; } break; case DLL_THREAD_ATTACH: break; case DLL_THREAD_DETACH: break; case DLL_PROCESS_DETACH: break; default: //OutputDebugString("Not sure what just happened.\n"); break; } return TRUE; } ///////////////////// //////////////////////////"HookCore.h" #pragma once LRESULT CALLBACK GetMessageProc(int nCode, WPARAM wParam, LPARAM lParam); bool InitializeHook(); void UninitializeHook(); //////////////// //////////////////////////"HookCore.cpp" #include "stdafx.h" #include <windows.h> #include "HookCore.h" #include "MessageFilter.h" HHOOK hookMsg = NULL; HINSTANCE g_appInstance = NULL; LRESULT CALLBACK GetMessageProc(int nCode, WPARAM wParam, LPARAM lParam){ if (nCode == HC_ACTION) { MSG *msg = (MSG *) lParam; if(msg->message == WM_PAINT){ //Beep debug Beep(1000,1); //Write file debug } //Process message //... } return CallNextHookEx (hookMsg, nCode, wParam, lParam); } bool InitializeHook() { if (g_appInstance == NULL) { return false; } hookMsg = SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC)GetMessageProc, g_appInstance, 0); return hookMsg != NULL; } void UninitializeHook() { if(hookMsg != NULL) { UnhookWindowsHookEx(hookMsg); } hookMsg = NULL; } ///////////////////////////////////////////////// ///////////////////////"HookCore.def" LIBRARY "HookLib" EXPORTS InitializeHook UninitializeHook ////////////////////////////////////////////////////////////////////////// and my C# code to import dll functions is DllImport("HookLib.dll", EntryPoint="InitializeHook", SetLastError=true, CharSet=CharSet.Unicode, ExactSpelling=true, CallingConvention=CallingConvention.StdCall)] private static extern bool InitializeHook(); [DllImport("HookLib.dll", EntryPoint="UninitializeHook", SetLastError=true, CharSet=CharSet.Unicode, ExactSpelling=true, CallingConvention=CallingConvention.StdCall)] private static extern void UninitializeHook(); then i use the InitializeHook() method i got the above exception can somebody tell me how i can get rid of this Thanx for ur response.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this