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

Asked

Viewed 561 times

3

I’m migrating a project to C++, but I’m having trouble calling . 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; 
}

Error is found in "=" of Handle:

" Intellisense: a value of type "HMODULE" cannot be assigned to an entity of type "int""

What I’m doing wrong, and what they recommend ?

  • 1

    What is the problem you are having with the current code? PS: do not need (or should) declare Handle 2x as char.

  • I have error in Loadlibrary, :Error: HMODULE

  • Do the following, edit the question and put all the relevant details, so that someone can help. Read the linked page here for some cool tips: [Ask]

  • Okay, I’ll take a hint... Thank you...

  • HMODULE is probably the following: in that case, it would have to be HMODULE handle; in place of char handle;. And only declare once.

  • Okay, I’ll check here!

Show 1 more comment

1 answer

3


From the comments, I believe the problem is in Handle’s statement:

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 changed the verification code for the error case, see if that’s what you want.

  • Yes, I made this change, but in the case of the Return Handle, I had to define as char(Handle), then it worked!

  • Use HMODULE LoadDLL(void) in place of int LoadDLL (void), not to need this cast.

  • It also worked!!!

  • Thank you very much, Bacco!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.