[C++] DLL importen (noob)

Pagina: 1
Acties:
  • 54 views sinds 30-01-2008

  • DieterVDW
  • Registratie: Juli 2002
  • Laatst online: 12-02-2017
Ik ben nu al een paar uur bezig om te proberen een functie
te importen uit een DLL en die dan uit te voeren en
de pointer die deze functie teruggeeft op te slaan.
Gewoon de functie uitvoeren is geen probleem,
dan doe ik gewoon

code:
1
2
    __declspec ( dllimport ) In_Module * (ProcAdd)();
    (ProcAdd) ();


maar zodra ik 'inmod = ' voor die (ProcAdd) () zet,
om dus de pointer op te slaan die (ProcAdd) () teruggeeft, wil 'm niet meer.
Dan begint 'm plots te klagen over unresolved externals ...

code:
1
2
3
SimplePlayer.obj : error LNK2001: unresolved external symbol \
 "__declspec(dllimport) struct In_Module * __cdecl ProcAdd(void)" (__imp_?ProcAdd@@YAPAUIn_Module@@XZ)
Debug/SimplePlayer.exe : fatal error LNK1120: 1 unresolved externals


Het zal wel duidelijk zijn dat ik redelijk noob ben op C++ gebied,
en dus had ik nu graag eens geweten wat de 'correcte' manier is
om dat af te handelen.

(Ik heb me trouwens echt al rot gezocht op Google en msdn,
maar niks gevonden dat helpt...)

Jullie hulp wordt héél erg gewaardeerd...

Hieronder eens het volledige stuk voor de duidelijkheid:
(als het te lang is zeg het dan hé, dan edit dit wel weg)

C++:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
typedef VOID (*MYPROC)(LPTSTR); 
 
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
    LPSTR lpCmdLine, int nCmdShow)
{ 
    HINSTANCE hinstLib; 
    BOOL fFreeResult, fRunTimeLinkSuccess = FALSE; 
    MYPROC ProcAdd;
 
    // Get a handle to the DLL module.
     hinstLib = LoadLibrary(plugin); 
 
    // If the handle is valid, try to get the function address.
     if (hinstLib != NULL) 
    { 
        MessageBox(NULL, "Start!", "Note", MB_OK);
        ProcAdd = (MYPROC) GetProcAddress(hinstLib, callfunc); 
 
        // If the function address is valid, call the function.
         if (NULL != ProcAdd) 
        {
            MessageBox(NULL, "DLL Loaded!", "Note", MB_OK);
            fRunTimeLinkSuccess = TRUE; 
            In_Module* inmod;
            __declspec ( dllimport ) In_Module * (ProcAdd)();
            inmod = (ProcAdd) ();
        }
        
         // Free the DLL module.
         fFreeResult = FreeLibrary(hinstLib); 
    } 

    return 0;
}

[ Voor 11% gewijzigd door DieterVDW op 01-09-2003 15:20 ]


  • DieterVDW
  • Registratie: Juli 2002
  • Laatst online: 12-02-2017
Ok dankzij de hulp van luite op #tweakers.net heb ik het gevonden:
typedef VOID (*MYPROC)(LPTSTR);
wordt
typedef In_Module* (*MYPROC)();

en regel 25 mag geschrapt worden.

Et voila! Ca marche!!

  • curry684
  • Registratie: Juni 2000
  • Laatst online: 13-08 16:46

curry684

left part of the evil twins

Manual.

Professionele website nodig?


Dit topic is gesloten.