473,395 Members | 2,079 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,395 software developers and data experts.

Struct to Byte

Hello,

this my problem:
I have a struc, but i would like to know how can i do to convert it in byte.

This is my code:

[DllImport("winspool.drv", EntryPoint = "AddMonitor")]
public static extern int AddMonitorA(string pName, int Level, ref byte
pMonitors);

[StructLayout(LayoutKind.Sequential)]
public struct MONITOR_INFO_2
{
public string pName;
public string pEnvironment;
public string pDLLName;
}

AddMonitorA(null, 2,ref ???);

Thank you,

Best regards,

Wavemill
May 16 '06 #1
1 2337
wavemill,

Two things. The first is that I would not specifically point to the
AddMonitorA function. The declaration I would use is this:

[DllImmport("winspool.drv", CharSet=CharSet.Auto)]
public static extern bool AddMonitor(string pName, int Level, ref
MONITOR_INFO_2 pMonitors);

The P/Invoke layer will call the right function
(AddMonitorA/AddMonitorW) based on the platform the code is being run on.
Additionally, you can declare the last parameter as the type you want to
pass. Since the parameter is just a pointer, you can pass any kind you
want. When you use ref, the marshaler considers it a pointer to a structure
and it marshals it appropriately.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"wavemill" <wa******@discussions.microsoft.com> wrote in message
news:5D**********************************@microsof t.com...
Hello,

this my problem:
I have a struc, but i would like to know how can i do to convert it in
byte.

This is my code:

[DllImport("winspool.drv", EntryPoint = "AddMonitor")]
public static extern int AddMonitorA(string pName, int Level, ref byte
pMonitors);

[StructLayout(LayoutKind.Sequential)]
public struct MONITOR_INFO_2
{
public string pName;
public string pEnvironment;
public string pDLLName;
}

AddMonitorA(null, 2,ref ???);

Thank you,

Best regards,

Wavemill

May 16 '06 #2

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

Similar topics

0
by: Josiah Carlson | last post by:
Good day everyone, I have produced a patch against the latest CVS to add support for two new formatting characters in the struct module. It is currently an RFE, which I include a link to at the...
67
by: S.Tobias | last post by:
I would like to check if I understand the following excerpt correctly: 6.2.5#26 (Types): All pointers to structure types shall have the same representation and alignment requirements as each...
36
by: Eric Laberge | last post by:
Hi! I'm working on automatically generated code, and need to assign arrays. memcpy is an obvious solution, but it becomes complicated to use in the context I'm working on, ie.: I could use it...
3
by: Dirk Reske | last post by:
Hello, I have the following struct: public struct WAVEFORMATEX { public UInt16 wFormatTag; //2 bytes public UInt16 nChannels; //2 bytes public UInt32 nSamplesPerSec; //4 bytes...
0
by: William Stacey | last post by:
The following code works, but I can't figure out why. I take a struct with two members, a single byte and byte. I then marshal the whole struct to a byte. I create a new struct (without init'ing...
8
by: Ben Terry | last post by:
What's the most efficient way to transfer data from a byte to a struct? The struct is rather complex--contains other structs as well as byte members. I've tried to use Marshal.Copy and an IntPtr...
1
by: Marquee | last post by:
Hello, This is my first program c#, my background is c++. One thing I would like to do is put binary data (e.g. a record from disk, or network packet) in a struct. In C++ I would create the...
1
by: jsshah | last post by:
Hi I want to marshal following Win32 struct into .NEt class or struct as I want to call a native dll function from a Csharp code. The win32 struct ----------------------- typedef struct...
2
by: CppTOCsharp | last post by:
Hi dudes, I´m trying to extern a C++ struct to C#, but its logging a problem in C# the log is: The code is: C++ struct: typedef struct CK_TOKEN_INFO { CK_CHAR label; /*...
0
by: ambeer | last post by:
Hello, i have created the struct: #region PacketStructures struct MainPacket { HeaderData headerData; public byte moduleType; ...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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.