DDE in C# .NET

  • Thread starter Thread starter M K via .NET 247
  • Start date Start date
M

M K via .NET 247

I've got this code:
(Library GMDDE.dll)
namespace GMDDE {
delegate Int32 DDECall(Int32 uiType, Int32 uiFmt, Int32 hConv,
Int32 sz1, Int32 sz2, Int32 hData, Int32 lData1, Int32 lData2);
public class GMDDEClass {
[DllImport("user32", EntryPoint="DdeInitializeA")]
private static extern Int32 DdeInitialize(Int32 pidInst, DDECall pfnCallback,
Int32 afCmd, Int32 ulRes);
private const Int32 DMLERR_NO_ERROR = 0x0000;
private const Int32 APPCMD_CLIENTONLY = 0x00000010;
public bool InitDDE(Int32 hConv, Int32 lIdLocal) {
DDECall GMDDEDelegat = new DDECall(DDECallback);
if (DdeInitialize(lIdLocal, GMDDEDelegat, APPCMD_CLIENTONLY, 0) != DMLERR_NO_ERROR) {
return false;
}
else {
return true;
}
}
public static Int32 DDECallback(Int32 uiType, Int32 uiFmt, Int32 hConv,
Int32 sz1, Int32 sz2, Int32 hData, Int32 lData1, Int32 lData2) {
return 1;
}
}
}
and here is calling in another project:
(application ProdCat.exe)
...
GMDDE.GMDDEClass GMDDEInstance = new GMDDE.GMDDEClass();
Int32 hConv = 0;
Int32 lIdLocal = 0;
if (GMDDEInstance.InitDDE(hConv, lIdLocal) == false) {
MessageBox.Show("Wyst?pi? b??d podczas inicjalizacji DDE!",
"B??d inicjalizacji DDE",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else {
MessageBox.Show("Inicjalizacja DDE powiod?a si?!",
"DDE zainicjowane",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
...
Compilation is successfull, but I get an exception:
System.NullReferenceException in GMDDE.dll (line: ...DDEInitialize...)

Where I make a mistake?
 
M said:
I've got this code:
(Library GMDDE.dll)
namespace GMDDE {
delegate Int32 DDECall(Int32 uiType, Int32 uiFmt, Int32 hConv,
Int32 sz1, Int32 sz2, Int32 hData, Int32 lData1, Int32 lData2);
public class GMDDEClass {
[DllImport("user32", EntryPoint="DdeInitializeA")]
private static extern Int32 DdeInitialize(Int32 pidInst, DDECall pfnCallback,
Int32 afCmd, Int32 ulRes);
private const Int32 DMLERR_NO_ERROR = 0x0000;
private const Int32 APPCMD_CLIENTONLY = 0x00000010;
public bool InitDDE(Int32 hConv, Int32 lIdLocal) {
DDECall GMDDEDelegat = new DDECall(DDECallback);
if (DdeInitialize(lIdLocal, GMDDEDelegat, APPCMD_CLIENTONLY, 0) != DMLERR_NO_ERROR) {
return false;
}
else {
return true;
}
}
public static Int32 DDECallback(Int32 uiType, Int32 uiFmt, Int32 hConv,
Int32 sz1, Int32 sz2, Int32 hData, Int32 lData1, Int32 lData2) {
return 1;
}
}
}
and here is calling in another project:
(application ProdCat.exe)
..
GMDDE.GMDDEClass GMDDEInstance = new GMDDE.GMDDEClass();
Int32 hConv = 0;
Int32 lIdLocal = 0;
if (GMDDEInstance.InitDDE(hConv, lIdLocal) == false) {
MessageBox.Show("Wyst?pi? b??d podczas inicjalizacji DDE!",
"B??d inicjalizacji DDE",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else {
MessageBox.Show("Inicjalizacja DDE powiod?a si?!",
"DDE zainicjowane",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
..
Compilation is successfull, but I get an exception:
System.NullReferenceException in GMDDE.dll (line: ...DDEInitialize...)

I believe the mistake is that DdeInitialize takes an pointer to an int,
not an int. You're then passing NULL as the pointervalue (Int32 lIdLocal
= 0;)
when the doc says that: At initialization, this parameter should
*point* to 0.

hth
 
Back
Top