473,320 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 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 1458
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Kenny | last post by:
Hello, can anyone tell me how to pass an array to a function ? I have this function , part of my class. It works if I do not put in int a everywhere , but obviously , I need to add an array so I...
110
by: Mr A | last post by:
Hi! I've been thinking about passing parameteras using references instead of pointers in order to emphasize that the parameter must be an object. Exemple: void func(Objec& object); //object...
7
by: ritchie | last post by:
Hi all, I am new to this group and I have question that you may be able to help me with. I am trying to learn C but am currently stuck on this. First of all, I have a function for each sort...
8
by: Blue Ocean | last post by:
I know this is somewhat dependent on the circumstances, but let me ask anyway. Suppose I have a 100 byte struct or array or something like that. Which would be more efficient? void...
10
by: nospam | last post by:
Hello! I can pass a "pointer to a double" to a function that accepts double*, like this: int func(double* var) { *var=1.0; ... }
14
by: Abhi | last post by:
I wrote a function foo(int arr) and its prototype is declared as foo(int arr); I modify the values of the array in the function and the values are getting modified in the main array which is...
10
by: Robert Dailey | last post by:
Hi, I noticed in Python all function parameters seem to be passed by reference. This means that when I modify the value of a variable of a function, the value of the variable externally from the...
6
by: lisp9000 | last post by:
I've read that C allows two ways to pass information between functions: o Pass by Value o Pass by Reference I was talking to some C programmers and they told me there is no such thing as...
11
by: venkatagmail | last post by:
I have problem understanding pass by value and pass by reference and want to how how they are or appear in the memory: I had to get my basics right again. I create an array and try all possible...
4
by: S. | last post by:
Hi all, I have the requirement that I must pass-by-reference to my function addStudent() and getAge() functions where my getAge() function is within the addStudent() function. I am able to...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.