H
Homa
Hi all,
I'm writing a DDEML wrapper in C#.
I'm able to establish a connection to the server application but
when I try to disconnect it using DdeDisconnect, I got an error
message DMLERR_INVALIDPARAMETER.
I looked at the spec of the function
(http://msdn.microsoft.com/library/d...ExchangeManagementFunctions/DdeDisconnect.asp)
and see that the error message I could get are
DMLERR_DLL_NOT_INITIALIZED, DMLERR_NO_CONV_ESTABLISHED, and
DMLERR_NO_ERROR.
I don't know why would the error DMLERR_INVALIDPARAMETER show up at
this place.
I tested it and indeed it comes from the DdeDisconnect call.
There is the boilerplate of the coding,
internal class ddeClass
{
[DllImport("user32")]
internal static extern bool DdeDisconnect(ref int hConv);
[DllImport("user32")]
internal static extern int DdeConnect(int idInst, int hszService, int
hszTopic, out CONVCONTEXT pCC);
[DllImport("user32")]
internal static extern int DdeCreateStringHandle(int idInst, string
psz, int iCodePage);
[DllImport("user32")]
internal static extern DMLERR DdeGetLastError(int idInst);
}
internal class ddeTest
{
int idInst = 0; // This is properly initialized in the constructor
// by calling ddeClass.DdeInitialize (not shown)
int hszService = 0;
int hszTopic = 0;
int conHandle = 0;
private void button3_Click(object sender, System.EventArgs e)
{
ddeClass.CONVCONTEXT ccontext;
// I use Excel to test the program. An instance of excel is opened
// when this test program runs.
hszService = ddeClass.DdeCreateStringHandle(idInst, "Excel",
ddeClass.CP_WINANSI);
hszTopic = ddeClass.DdeCreateStringHandle(idInst, "Sheet1",
ddeClass.CP_WINANSI);
conHandle = ddeClass.DdeConnect(idInst, hszService, hszTopic, out
ccontext);
// I get a non-zero conHandle here, the connection success
// Also, if call ddeClass.DdeGetLastError here, I get
DMLERR_NO_ERROR
ddeClass.DdeDisconnect(ref conHandle);
ddeClass.DMLERR derr = ddeClass.DdeGetLastError(idInst);
label1.Text = Enum.GetName(typeof(ddeClass.DMLERR), derr);
// label1.Text => DMLERROR_INVALIDPARAMETER
}
}
Thanks for concern,
Homa Wong
I'm writing a DDEML wrapper in C#.
I'm able to establish a connection to the server application but
when I try to disconnect it using DdeDisconnect, I got an error
message DMLERR_INVALIDPARAMETER.
I looked at the spec of the function
(http://msdn.microsoft.com/library/d...ExchangeManagementFunctions/DdeDisconnect.asp)
and see that the error message I could get are
DMLERR_DLL_NOT_INITIALIZED, DMLERR_NO_CONV_ESTABLISHED, and
DMLERR_NO_ERROR.
I don't know why would the error DMLERR_INVALIDPARAMETER show up at
this place.
I tested it and indeed it comes from the DdeDisconnect call.
There is the boilerplate of the coding,
internal class ddeClass
{
[DllImport("user32")]
internal static extern bool DdeDisconnect(ref int hConv);
[DllImport("user32")]
internal static extern int DdeConnect(int idInst, int hszService, int
hszTopic, out CONVCONTEXT pCC);
[DllImport("user32")]
internal static extern int DdeCreateStringHandle(int idInst, string
psz, int iCodePage);
[DllImport("user32")]
internal static extern DMLERR DdeGetLastError(int idInst);
}
internal class ddeTest
{
int idInst = 0; // This is properly initialized in the constructor
// by calling ddeClass.DdeInitialize (not shown)
int hszService = 0;
int hszTopic = 0;
int conHandle = 0;
private void button3_Click(object sender, System.EventArgs e)
{
ddeClass.CONVCONTEXT ccontext;
// I use Excel to test the program. An instance of excel is opened
// when this test program runs.
hszService = ddeClass.DdeCreateStringHandle(idInst, "Excel",
ddeClass.CP_WINANSI);
hszTopic = ddeClass.DdeCreateStringHandle(idInst, "Sheet1",
ddeClass.CP_WINANSI);
conHandle = ddeClass.DdeConnect(idInst, hszService, hszTopic, out
ccontext);
// I get a non-zero conHandle here, the connection success
// Also, if call ddeClass.DdeGetLastError here, I get
DMLERR_NO_ERROR
ddeClass.DdeDisconnect(ref conHandle);
ddeClass.DMLERR derr = ddeClass.DdeGetLastError(idInst);
label1.Text = Enum.GetName(typeof(ddeClass.DMLERR), derr);
// label1.Text => DMLERROR_INVALIDPARAMETER
}
}
Thanks for concern,
Homa Wong