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;
} 1 1823
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;
} This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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;
...
}
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |