473,396 Members | 1,915 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,396 software developers and data experts.

Returning data in LParam to Unmanaged Code

Hello,

I am currently trying to respond to custom messages sent via
SendMessage/PostMessage from my unmanaged C++ dll in my C#
application.

I am responding to these types of messages by overriding WndProc
function in my C# form. This works fine until I attempt to populate an
LPARAM with a string so that my unmanaged code can use that string.
That Lparam property of the passed in message object is of type
IntPtr. How can I cast/convert that to a string? And, moreover, how do
I get that string down to my unmanaged code in the context of that
LParam? I would ideally not want to change my unmanaged code to handle
this.

Does someone out there know how to accomplish this? Code samples are
appreciated.

- Bruce
Nov 15 '05 #1
3 2314
How are you declaring the method on C# ?

Have you tried this instead of IntPtr:

[DllImport(...)]
public static extern void Whatever(StringBuffer lparam);
HTH
Brian W

"BruceR" <br******@msn.com> wrote in message
news:e2**************************@posting.google.c om...
Hello,

I am currently trying to respond to custom messages sent via
SendMessage/PostMessage from my unmanaged C++ dll in my C#
application.

I am responding to these types of messages by overriding WndProc
function in my C# form. This works fine until I attempt to populate an
LPARAM with a string so that my unmanaged code can use that string.
That Lparam property of the passed in message object is of type
IntPtr. How can I cast/convert that to a string? And, moreover, how do
I get that string down to my unmanaged code in the context of that
LParam? I would ideally not want to change my unmanaged code to handle
this.

Does someone out there know how to accomplish this? Code samples are
appreciated.

- Bruce

Nov 15 '05 #2
Does someone out there know how to accomplish this?


So the message sender passes you a buffer pointer in the lParam and
you want to copy a string to that buffer? You can do that with the
Marshal.Copy method (first convert the string to a char[] or byte[] as
needed) or using the Win32 API function CopyMemory.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 15 '05 #3
Mattias,

Yes, that is correct. I used the Marshal.Copy method as you have
suggested and that did the trick. Thanks a bunch!

- Bruce
Mattias Sjögren <ma********************@mvps.org> wrote in message news:<ej**************@TK2MSFTNGP12.phx.gbl>...
Does someone out there know how to accomplish this?


So the message sender passes you a buffer pointer in the lParam and
you want to copy a string to that buffer? You can do that with the
Marshal.Copy method (first convert the string to a char[] or byte[] as
needed) or using the Win32 API function CopyMemory.

Mattias

Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Devon Reed | last post by:
I'm trying to create a simple program in Visual C++ to output the results of a gethostbyname function call. However, my program is crashing, and the problem seems to be with retrieving the data...
2
by: Philippe F. Bertrand | last post by:
Summary - What should a C# bool map to in C++? Are return types different? I have lots of methods declared with bool parameters and bool return type which appear to work without any problems...
7
by: sienaman | last post by:
I have a C# dll with a COM interface that is successfully call by a C++ client. One of the parameters is a string, the method looks like void Goofy(string strUserInput, out string strOutput); ...
5
by: Mark Ingram | last post by:
Hi, how can i return an array of strings from an unmanaged c++ dll into a c# application? cheers Mark
0
by: Johannes Unfried | last post by:
Problem Best practice needed to marshal STL data from managed code to unmanaged code & vice vers Details managed code is written in managed C++ & accesses the unmanaged code (i.e. lives in a...
8
by: MyAlias | last post by:
Can't solve this CallBack returning structures Error message: An unhandled exception of type 'System.NullReferenceException' occurred in MyTest.exe Additional information: Object reference not...
7
by: ConfNoob | last post by:
part 1: there is a NON - COM unmanaged dll in VC++ 6.0 BOOL function(char * name, int nOption) part 2: there is a C# web service that has to consume the above DLL used DLLImport to call the...
0
by: rkpatil | last post by:
have an unmanaged C++ DLL with following method: the DLL interface for unmanaged C++ is: SendCommand(void *h, char *c, char *d, char *b); the declaration in C# is: unsafe public static...
7
by: dzar | last post by:
I have an application that sends messages to other applications through PostMessage(HWND_BROADCAST, MY_MESSAGE_ID, wparam_float, lparam_float); in C (and this works... I can typecast and built byte...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.