471,123 Members | 865 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,123 software developers and data experts.

how to pass a POINTER to an int to a DLL function

I'm trying to use the DdeInitialize() function from an external DLL in my C#
code. The first parameter is described as LPDWORD, which seems to be a
pointer to a DWORD. I believe that the DWORD is equivalent to UInt32.

The MarshalAs attribute does not seem to have a pointer type available. How
do I pass an integer pointer to the external DLL function?

I've attached the code I have so far below.

Thanks for any suggestions.

Dale

[System.Runtime.InteropServices.DllImport("User32.D LL")]

public static extern System.UInt32 DdeInitialize(

[System.Runtime.InteropServices.MarshalAs(System.Ru ntime.InteropServices.Unm
anagedType.U4)]

System.UInt32 pidInst, //LPDWORD pidInst,

[System.Runtime.InteropServices.MarshalAs(System.Ru ntime.InteropServices.Unm
anagedType.FunctionPtr)]

DDE_CallBack_delegate pfnCallback, //PFNCALLBACK pfnCallback,

System.UInt32 afCmd, //DWORD afCmd,

System.UInt32 ulRes //DWORD ulRes

);

public static int Send_Message_To_Toolbox_Server(string as_Command_Line)

{

System.UInt32 lui32_rc;

System.UInt16 lui16_App_Instance_Id;

System.IntPtr lptr_App_Instance_Id;

System.UInt32 lui32_afCmd;

System.UInt32 lui32_ulRes;

const System.UInt32 APPCMD_CLIENTONLY = (System.UInt32)0x00000010L;

// APPCMD_CLIENTONLY 0x00000010L

// Declare and get pointer to callback function

DDE_CallBack_delegate myDelegate = new
DDE_CallBack_delegate(DDEMLWrapper.ApplicationLaun cher_DdeCallback);


// Initialize this application for DDE communication

lui16_App_Instance_Id = 0;

lptr_App_Instance_Id = (System.IntPtr)lui16_App_Instance_Id;

lui32_afCmd = APPCMD_CLIENTONLY;

lui32_ulRes = 0;

lui32_rc = DdeInitialize(lptr_App_Instance_Id, myDelegate, lui32_afCmd,
lui32_ulRes);


// Send as_Command_Line to the server

return 0;

}
Jul 21 '05 #1
1 1384
Yes, LPWORD is a pointer to a DWORD. To call DdeInitialize you need to use a
reference to a uint (i.e. ref uint pidInst).

HTH, Jakob.

"Dale" wrote:
I'm trying to use the DdeInitialize() function from an external DLL in my C#
code. The first parameter is described as LPDWORD, which seems to be a
pointer to a DWORD. I believe that the DWORD is equivalent to UInt32.

The MarshalAs attribute does not seem to have a pointer type available. How
do I pass an integer pointer to the external DLL function?

I've attached the code I have so far below.

Thanks for any suggestions.

Dale

[System.Runtime.InteropServices.DllImport("User32.D LL")]

public static extern System.UInt32 DdeInitialize(

[System.Runtime.InteropServices.MarshalAs(System.Ru ntime.InteropServices.Unm
anagedType.U4)]

System.UInt32 pidInst, //LPDWORD pidInst,

[System.Runtime.InteropServices.MarshalAs(System.Ru ntime.InteropServices.Unm
anagedType.FunctionPtr)]

DDE_CallBack_delegate pfnCallback, //PFNCALLBACK pfnCallback,

System.UInt32 afCmd, //DWORD afCmd,

System.UInt32 ulRes //DWORD ulRes

);

public static int Send_Message_To_Toolbox_Server(string as_Command_Line)

{

System.UInt32 lui32_rc;

System.UInt16 lui16_App_Instance_Id;

System.IntPtr lptr_App_Instance_Id;

System.UInt32 lui32_afCmd;

System.UInt32 lui32_ulRes;

const System.UInt32 APPCMD_CLIENTONLY = (System.UInt32)0x00000010L;

// APPCMD_CLIENTONLY 0x00000010L

// Declare and get pointer to callback function

DDE_CallBack_delegate myDelegate = new
DDE_CallBack_delegate(DDEMLWrapper.ApplicationLaun cher_DdeCallback);


// Initialize this application for DDE communication

lui16_App_Instance_Id = 0;

lptr_App_Instance_Id = (System.IntPtr)lui16_App_Instance_Id;

lui32_afCmd = APPCMD_CLIENTONLY;

lui32_ulRes = 0;

lui32_rc = DdeInitialize(lptr_App_Instance_Id, myDelegate, lui32_afCmd,
lui32_ulRes);


// Send as_Command_Line to the server

return 0;

}

Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Kenny | last post: by
7 posts views Thread by ritchie | last post: by
8 posts views Thread by Blue Ocean | last post: by
14 posts views Thread by Abhi | last post: by
10 posts views Thread by Robert Dailey | last post: by
6 posts views Thread by lisp9000 | last post: by
4 posts views Thread by S. | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.