I'm trying to import a function exported by a dll. So far:

#pragma comment(lib, "hookHop.lib")

extern "C"  void hhPostMessageA(HWND Hwn, UINT Msg, WPARAM WParam, LPARAM LParam); 
extern "C"  LPARAM CursorPosTolParam(VOID);

The lib and dll are in my project directory and my dll is in my debug directory. I get the following linker error when I build:

main.obj : error LNK2019: unresolved external symbol _hhPostMessageA referenced in function "void __cdecl SendKey(char)" (?SendKey@@YAXD@Z)
main.obj : error LNK2019: unresolved external symbol _CursorPosTolParam referenced in function "long __cdecl getCursPos(void)" (?getCursPos@@YAJXZ)

Unfortunately the person who did it only uses assembly lol. Here's what's in the .def file:

LIBRARY  hookHop
EXPORTS  CursorPosTolParam
EXPORTS  hhPostMessageA

he did release the source. here's hhPostMessageA's func defintion:

hhPostMessageA proc    hWnd:HWND, Msg:UINT, wParam:WPARAM, lParam:LPARAM
    cmp     dword ptr ds:[boolVersion], 01h
    jz      @f
    mov     edi, edi
    push    ebp
    mov     ebp, esp
    jmp     dword ptr ds:[adrPostMessage]

    @@:
    mov     dword ptr [eax], 01234h
    ret     
hhPostMessageA endp

Help?

The compiler is mangling your function name to "C" standards. It is looking for "_hhPostMessageA" instead of "hhPostMessageA" (note the underscore).

What you are doing is fairly compiler-specific, but these days a lot of them accept the __declspec keyword. extern "C" __declspec( dllimport ) void hhPostMessageA( HWND, UINT, WPARAM, LPARAM ); (I've not done this in C++ before, so this example might not be quite right. But even if it is, it might not be quite right for your compiler.)

Hope this helps.

Hi

I am using Microsoft Visual Studio C++ 6.0, MFC, and hookHop.dll

This is what I did:

1. To load hookHop DLL into memory and obtain a function pointer to hhPostMessageA

// Function pointer type for hhPostMessageA in hookHop DLL
typedef int (__stdcall *HHPtr) (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
.
.
.
HINSTANCE m_hInst; // Instance of hookHop DLL
HHPtr m_phhPostMessageA; // Function pointer to hhPostMessageA
.
.
.
// Load hookHop DLL
m_hInst = ::LoadLibrary("hookHop.dll");

if (m_hInst != NULL) {
   // Get function pointer to hhPostMessageA
   m_phhPostMessageA = (HHPtr)GetProcAddress(m_hInst, "hhPostMessageA");
}

2. To unload hookHop DLL when AutoClick terminates

if (m_hInst != NULL) {
   // Un-Load hookHop DLL
   ::FreeLibrary(m_hInst);
   m_hInst = NULL;
}

3. To generate 't' key down event

HWND m_cHandle; // Windows handle to MapleStory
UINT scancode;
LPARAM lparam;
.
.
.
// Get window handle on MapleStory
m_cHandle = ::FindWindow("MapleStoryClass", NULL);

if ((m_cHandle != NULL) && (m_phhPostMessageA != NULL)) {

   // 0x54 is virtual key code for 't'
   scancode = MapVirtualKey(0x54, 0);

   // The scancode value is in the low 16 bits
   // need to shift it to the left 16 bits.
   // + 1 is the number of repetition.
   lparam = (scancode << 16) + 1;

   m_phhPostMessageA(m_cHandle, WM_KEYDOWN, NULL, lparam);

   // This call will only generate key press t in textboxes
   //m_pFunc(m_cHandle, WM_KEYDOWN, 0x54, NULL);

   // This call will generate key press t in both textboxes
   // and the graphic screen.
   //m_pFunc(m_cHandle, WM_KEYDOWN, 0x54, lparam);			
}

I hope this helps.

This article has been dead for over six months. Start a new discussion instead.