How do I call a .dll and declare functions in C++.Net

Question:

I'm migrating a project to C++, but I'm having trouble calling the .dll

This is code:

int  LoadDLL (void) {
   char handle;

   //! Carrega a dll ...
   handle = LoadLibrary(L"c:\windows\system\minhadll.dll");

   //! Verifica se a dll foi corretamente carregada..
   if (handle) {

   }
   return handle; 
}

The error is found in the "=" of the handle:

" IntelliSense: A value of type "HMODULE" cannot be assigned to an entity of type "int""

What am I doing wrong, and what do you recommend?

Answer:

From the comments, I believe the problem is in the handle declaration:

HMODULE LoadDLL(void) {
   HMODULE handle;

   // Carrega a dll ...
   handle = LoadLibrary(L"c:\windows\system\minhadll.dll");

   // Verifica se a dll foi corretamente carregada..
   if (handle == NULL) {
      //Indicar que deu erro
   }
   return handle; 
}

Note that I've changed the verification code for the error case, see if that's what you want.

Scroll to Top