By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,168 Members | 1,492 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,168 IT Pros & Developers. It's quick & easy.

Struct to Byte

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.