473,468 Members | 1,389 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Porting from C++, p/Invoke with structs, SendMessage() and WM_COPYDATA

Hi,

I'm trying to port a c++ class to c# and in the c++ class I have a
struct defined as:
struct SNARLSTRUCT {
SNARL_COMMANDS cmd;
long id;
long timeout;
long lngData2;
char title[SNARL_STRING_LENGTH];
char text[SNARL_STRING_LENGTH];
char icon[SNARL_STRING_LENGTH];
};

SNARL_COMMANDS is just an enum and SNARL_STRING_LENGTH in this case is
1024.

I've recreated the struct in c# as:

[StructLayout(LayoutKind.Sequential)]
public struct SNARLSTRUCT {
public SNARL_COMMANDS cmd;
public long id;
public long timeout;
public long lngData2;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=SNARL_STRING_LENGTH)]
public byte[] title;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=SNARL_STRING_LENGTH)]
public byte[] text;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=SNARL_STRING_LENGTH)]
public byte[] icon;
};

First of all, is this correct?
If it is, how do I go about moving data from a string to the byte
arrays and make sure they're a valid c-string representation.

Secondly, once this is correct and working, how do I use the struct as
the data part of a COPYDATASTRUCT to be sent to another window via
SendMessage() with the WM_COPYDATA message? I've seen lots of
examples on how to send simple types such as ints and strings, but not
structs.

Examples would be great (I'm a learn by example person) but pointing
to relevant docs would also be helpful.

Thanks,
Alex.

Feb 14 '07 #1
1 3520

why in the hell would you wat to keep C code?

why don't you just stick a big fat dildo up your ass, run around on
the streets and say 'look at me look at me I can take a pointer in my
ass'

'
On Feb 14, 1:43 am, alexwhit...@gmail.com wrote:
Hi,

I'm trying to port a c++ class to c# and in the c++ class I have a
struct defined as:
struct SNARLSTRUCT {
SNARL_COMMANDS cmd;
long id;
long timeout;
long lngData2;
char title[SNARL_STRING_LENGTH];
char text[SNARL_STRING_LENGTH];
char icon[SNARL_STRING_LENGTH];
};

SNARL_COMMANDS is just an enum and SNARL_STRING_LENGTH in this case is
1024.

I've recreated the struct in c# as:

[StructLayout(LayoutKind.Sequential)]
public struct SNARLSTRUCT {
public SNARL_COMMANDS cmd;
public long id;
public long timeout;
public long lngData2;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=SNARL_STRING_LENGTH)]
public byte[] title;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=SNARL_STRING_LENGTH)]
public byte[] text;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=SNARL_STRING_LENGTH)]
public byte[] icon;

};

First of all, is this correct?
If it is, how do I go about moving data from a string to the byte
arrays and make sure they're a valid c-string representation.

Secondly, once this is correct and working, how do I use the struct as
the data part of a COPYDATASTRUCT to be sent to another window via
SendMessage() with the WM_COPYDATA message? I've seen lots of
examples on how to send simple types such as ints and strings, but not
structs.

Examples would be great (I'm a learn by example person) but pointing
to relevant docs would also be helpful.

Thanks,
Alex.

Feb 14 '07 #2

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

Similar topics

8
by: g.franzkowiak | last post by:
Hello everybody, I've tryed to use an interprocess communication via SendMessage on Windows. Unfortunately, nothing goes on ...
2
by: Erik | last post by:
I am having trouble getting this to work so hopefully someone can provide some insite. I have a structure that I store in a CopyDataStruct which is then send to another application via...
2
by: James Burrow | last post by:
Hi, I am trying to write a 2 .net programs that can communicate via windows messages. I have achieved this but only just passing ints. When i try and pass a string, i get junk out. I guess this...
0
by: Augie | last post by:
Dear All, I came across this piece of code to send a message. I have this setup and running... getting all the WM_COPYDATA messages on the client side. However I can't see the contexts of the...
1
by: Daniel Halan | last post by:
Hello, I want to send a SendMessage(hwnd,...) to an another application containing eighter a "String" or a PIDL... I know that the pointer lives in its own process so the other app will have...
4
by: Sean | last post by:
I am trying to send a WM_COPYDATA message to another application in C#, ..NET 2.0. The other application receives the message, but only seems to see the first character of the string, does...
1
by: Thomas Kehl | last post by:
Hello. I use the fallowing Functions to send Message from one Application to another. This is working correct on a 32bit System. But on a 64Bit System, the Target-Application will no received...
14
by: Kerem Gümrükcü | last post by:
Hi, i want to emulate a (synchronous) BroadCastSystemMessage with EnumWindows and SendMessage. I dont want to use the BroadcastSystemMessage because it needs the SE_TCB_NAME Privilege (you...
1
by: xMetalDetectorx | last post by:
I have two C# Applications. The first application has to send 2 strings to the other application. The first string is just a simple string "abc", while the 2nd string contains a path...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
1
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.