Click here to Skip to main content
15,887,214 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: Debug or Release Pin
Stephane Rodriguez.5-Mar-03 5:29
Stephane Rodriguez.5-Mar-03 5:29 
GeneralLicensed Controls on Web Pages Pin
NigelSavidge4-Mar-03 4:53
NigelSavidge4-Mar-03 4:53 
GeneralPlease Heeelp - ShouldSerializeMyProperty problem Pin
Uriel Cohen4-Mar-03 3:01
Uriel Cohen4-Mar-03 3:01 
GeneralRe: Please Heeelp - ShouldSerializeMyProperty problem Pin
Bo Hunter16-Mar-03 17:05
Bo Hunter16-Mar-03 17:05 
GeneralRe: Please Heeelp - ShouldSerializeMyProperty problem Pin
Uriel16-Mar-03 18:14
Uriel16-Mar-03 18:14 
QuestionWhich .NET developer magazine? Pin
Oyvind Bratland4-Mar-03 2:24
Oyvind Bratland4-Mar-03 2:24 
GeneralWhere to get the COM+ Current Object Count Pin
Gaul3-Mar-03 9:23
Gaul3-Mar-03 9:23 
GeneralHelp: Unable To Copy Data (In Structure) from Unmanged MFC/C++ App to .NET Pin
Gaul3-Mar-03 9:05
Gaul3-Mar-03 9:05 
I need to copy and send the data in a private structure from an MFC app to a .NET app. Somehow, the following does not seem to work. When I use the WM_COPYDATA windows message as indicated below, it is not being received by the WndProc on the .NET side, but when I use a private message, it is received. Unfortunately, when I use the private message, the data seems not to be copied across and I get an assertion error for null data. WM_COPY is not received on the .NET side, but when a private message is used, it is received but then Marshal.PtrToStructure asserts reporting a null value.

Using COM interop is not an option. The client thinks that COM will slow things down as the function is called thousands of times.

Does any one have a suggestion, or a better approach?

Thanks

Gaul



****************************
ON THE MFC SIDE
****************************
////////////////////////////////////////////////////////////
// Increment is called on the MFC side
/////////////////////////////////////////Increment Counter
long CTSPerfMon::Increment(int objectID, int instID)
{
_msg.nMsgID = TS_MSG_INCREMENT;
_msg.nObjectID = objectID;
_msg.nInstID = instID;
_msg.nValue = -1;

return SendMessage();
}

// Send Message across to the .NET side module
long CTSPerfMon::SendMessage()
{
// Fill the WIN32 COPYDATASTRUCT structure

_copyData.dwData = _nPerfMsg; // Message identifier
_copyData.cbData = sizeof(_msg); // size of data
_copyData.lpData = &_msg; // data structure

// Call function, passing data in &_msg
long nRetCode = -1;
if ( _hPerfWnd != NULL )
{
HWND hWnd = GetForegroundWindow();
if (hWnd == NULL)
hWnd = GetDesktopWindow();
nRetCode = ::SendMessage( _hPerfWnd,
WM_COPYDATA, //private message works here
(WPARAM)(HWND) hWnd, //windows sending the data
(LPARAM)(LPVOID) &_msg);
}
return nRetCode;
}

****************************
ON THE C# .NET SIDE
****************************

protected override void WndProc(ref System.Windows.Forms.Message m)
{

if (m.Msg == (int) Msgs.WM_COPYDATA)
{

COPYDATASTRUCT copyData = (COPYDATASTRUCT) Marshal.PtrToStructure(m.LParam, typeof(COPYDATASTRUCT));
if ((object) copyData != null)
{
IntPtr nPerfMsg = copyData.dwData;
if (nPerfMsg.ToInt32() == _nPerfMsg)
{
TSMSG msg = (TSMSG) Marshal.PtrToStructure(copyData.lpData, typeof(TSMSG));
int nRetCode = ProcessMessage(ref msg);
m.Result = (IntPtr) nRetCode;
return;
}
}
}
base.WndProc(ref m);

}

Structure definition on the MFC C++ side
----------------------------------------
#ifdef __cplusplus
extern "C" { // Assume C declarations for C++
#endif

typedef struct tagTSMSG
{
int nMsgID;
int nObjectID;
int nValue;
int nInstID;
}TSMSG;

#ifdef __cplusplus
} // End of extern "C" {
#endif // __cplusplus


Structure definitions on the .NET side:
--------------------------------------
[StructLayout(LayoutKind.Sequential)]
public struct TSMSG
{
public int nMsgID;
public int nObjectID;
public int nValue;
public int nInstID;
}

[StructLayout(LayoutKind.Sequential)]
public struct COPYDATASTRUCT
{
public IntPtr dwData;
public int cbData;
public IntPtr lpData;
}






Gaulles
QuestionSystem.Drawing.Drawing3D? Pin
Ioncycle3-Mar-03 5:30
Ioncycle3-Mar-03 5:30 
AnswerRe: System.Drawing.Drawing3D? Pin
leppie3-Mar-03 8:59
leppie3-Mar-03 8:59 
GeneralRe: System.Drawing.Drawing3D? Pin
Ioncycle21-Mar-03 11:56
Ioncycle21-Mar-03 11:56 
GeneralInterop - Marshaling nested structs Pin
Nathan Tran2-Mar-03 19:03
Nathan Tran2-Mar-03 19:03 
GeneralRemoting over internet (events) Pin
Richard P S2-Mar-03 9:24
Richard P S2-Mar-03 9:24 
GeneralRe: Remoting over internet (events) Pin
John Davis2-Mar-03 10:48
John Davis2-Mar-03 10:48 
GeneralRe: Remoting over internet (events) Pin
Richard P S3-Mar-03 0:29
Richard P S3-Mar-03 0:29 
GeneralRe: Remoting over internet (events) Pin
John Davis3-Mar-03 4:33
John Davis3-Mar-03 4:33 
Generalwfc in J# Pin
ashwathi1-Mar-03 18:26
ashwathi1-Mar-03 18:26 
General.NET Serialization Pin
LindaK28-Feb-03 9:54
LindaK28-Feb-03 9:54 
QuestionHow to remove assembly at runtime Pin
nguyentuancuong27-Feb-03 15:06
nguyentuancuong27-Feb-03 15:06 
AnswerRe: How to remove assembly at runtime Pin
leppie28-Feb-03 6:13
leppie28-Feb-03 6:13 
QuestionWhere is SourceSafe 6.0 in .NET located?? Pin
IrishSonic27-Feb-03 12:24
IrishSonic27-Feb-03 12:24 
AnswerRe: Where is SourceSafe 6.0 in .NET located?? Pin
leppie28-Feb-03 6:15
leppie28-Feb-03 6:15 
GeneralExtensive API Library Pin
Poolbeer27-Feb-03 3:18
Poolbeer27-Feb-03 3:18 
GeneralRe: Extensive API Library Pin
leppie27-Feb-03 9:43
leppie27-Feb-03 9:43 
GeneralRe: Extensive API Library Pin
Poolbeer27-Feb-03 21:46
Poolbeer27-Feb-03 21:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.