| |

VerySource

 Forgot password?
 Register
Search
View: 1594|Reply: 5

Help: Why can't the function in the dynamic library be loaded

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-3-17 20:30:02
| Show all posts |Read mode
Dynamic library code:
extern "C" __declspec (dllexport) HWND __stdcall CreateCW (HWND);
int WINAPI DllEntryPoint (HINSTANCE hinst, unsigned long reason, void * lpReserved)
{
    return 1;
}
// ------------------------------------------------ ---------------------------
HWND __stdcall CreateCW (HWND MainWindowHandle)
{
  Application-> Handle = MainWindowHandle;
  Form2 = new TForm2 (NULL);
  SetParent (Form2-> Handle, MainWindowHandle);
  Form2-> ShowModal ();
  return Form2-> Handle;

}
Calling code:

    HINSTANCE hInstance;
    __showWindow show;
    if (hInstance == NULL)
    {
       hInstance = LoadLibrary ("Project2.dll");
    }
    if (hInstance! = NULL)
    {
     MessageBox (NULL, "BEGIN", "", 0);
     show = (__showWindow) GetProcAddress (hInstance, "CreateCW");
        if (NULL! = show)
       {
            hCwnd = show (Form1-> Handle);
       }
       else
       {
            MessageBox (NULL, "HANSHUJIAZAISHIBAI", "", 0);
       }
    }
    else
    {
        MessageBox (NULL, "Dynamic library loading failed", "", 0);
    }
Reply

Use magic Report

0

Threads

5

Posts

34.00

Credits

Newbie

Rank: 1

Credits
34.00

 China

Post time: 2020-4-9 16:23:12
| Show all posts
GetProcAddress (DLL, "_ CreateCW"); Add a "_".
Reply

Use magic Report

0

Threads

7

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-6-21 17:00:01
| Show all posts
There is no problem looking at the code, but I don’t see the definition of the __showWindow function pointer
What is wrong?
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-6-22 13:30:01
| Show all posts
Okay, I get it now
  HINSTANCE hInstance;
To be initialized, but now there are new problems, the program runs to
show(Form1->Handle );
The following problem appears
project project1.exe raised exception class EInvalidOperation with message'Cannot make a visible window modal'.process stopped
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-6-24 12:15:01
| Show all posts
if(NULL != show)
       {
            hCwnd = show(Application->Handle );
       }
Reply

Use magic Report

0

Threads

7

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-6-25 09:45:01
| Show all posts
The tips have all said, "Cannot make a visible window modal"
I think it’s the variable name, because "Form2" is a global variable that will be exported when the Form is created
Unless your Form2 is not automatically generated, otherwise Form2 can be used directly without writing new in the code
Try another variable name and try

I think it will be because Form2 already exists, although you have assigned a new instance to Form2. . .
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list