This is a problem I encountered when developing ioserver with C #.ProgramThe DLL originally developed with MFC needs to be used. The biggest problem is that some information during the DLL running process, and data is sent to the specified hwnd (Form handle) through the window message. The Data Pointer is placed in the wparam parameter, and the lparam parameter is the data type information.
C # provide M. the getlparam () function is a pity that my data is stored in the wparam parameter (this cannot be modified yet; otherwise, the original program cannot run and the modification cost is too high), so this function cannot be used.
After multiple tests, the data is obtained successfully.
Related in MFC DLLCode:
Tchar cmessage [255];
Systemtime stime;
Getlocaltime (& stime );
Swprintf (cmessage, _ T ("% 04d-% 02d-% 02d % 02d: % 02d: % 02d [%-16 s # % 03d]-% s "), stime. wyear, stime. wmonth, stime. wday, stime. whour, stime. wminute, stime. wsecond, strsource, lngno, strmessage );
If (g_iomrun.lngmsgflag = 0)
{
Sendmessage (g_iomrun.hwnd, wm_user+ 7722, (long) cmessage, lngtype );//
}
In C #, the message processing function of the form needs to be reloaded. The related code is as follows:
[Dllimport ("Kernel32", entrypoint = "copymemory")]
Public static extern void copymemory (stringbuilder destination, intptr source, int length );
/// <Summary>
/// Reload the Window Function
/// </Summary>
/// <Param name = "M"> </param>
Protected override void wndproc (ref message m)
{
//---------------------
If (M. MSG = 0x0400 + 7722)
{
Stringbuilder strdata = new stringbuilder (255 );
Copymemory (strdata, M. wparam, 255 );
Showinfo (INT) M. lparam, strdata. tostring ());
}
//---------------------
Base. wndproc (ref m );
}
Note: the Declaration of the copymemory function must be modified by yourself (the original declaration is as follows). You must remove the "Ref" keyword; otherwise, the result will be incorrect.
[Dllimport ("Kernel32", entrypoint = "copymemory")]
Public static extern void copymemory (
Ref int destination,
Ref int source,
Int Length
);