After trying out various methods, I couldn't get the below structure to
work. I read on some forum that combining value to type and reference type
in a [StructLayout(La youtKind.Explic it)] is not valid. And to implement a
union struct, we need to use [StructLayout(La youtKind.Explic it)]. If I
combine both the structures, the size of the structure rturned by
Marshal.SizeOf( ) is wrong. Does someone has an answer? Or is C# not capable
to handle this?
typedef ULONGLONG ADDR;
typedef struct _ADDRESS {
union {
ADDR ullLong;
BYTE rgBytes[ 6 ];
};
} ADDRESS_STRUCT;
typedef struct _DEVICE_INFO {
DWORD dwSize;
ADDR Address;
ULONG ulClassofDevice ;
BOOL fConnected;
BOOL fRemembered;
BOOL fAuthenticated;
SYSTEMTIME stLastSeen;
SYSTEMTIME stLastUsed;
WCHAR szName[ MAX_NAME_SIZE ];
} DEVICE_INFO_STR UCT;
[StructLayout(La youtKind.Sequen tial)]
internal struct DeviceInfo
{
internal uint dwSize;
[MarshalAs(Unman agedType.ByValA rray, SizeConst=6)]
internal byte[] address;
[MarshalAs(Unman agedType.ByValT Str, SizeConst = 248)]
internal string szName;
internal uint ulClassofDevice ;
internal ushort lmpSubversion;
internal ushort manufacturer;
internal ulong Addr
{
get
{
return (ulong)address[5] + ((ulong)address[4] << 8)
+ ((ulong)address[3] << 16) + ((ulong)address[2] << 24)
+ ((ulong)address[1] << 32) + ((ulong)address[0] << 40);
}
}
internal static DeviceInfo Create()
{
DeviceInfo di = new DeviceInfo();
di.address = new byte[] {34, 56, 56, 234, 12, 34};
//Returns a wrong size.
//This error is returned by GetDeviceInfo function
(ERROR_REVISION _MISMATCH)
//The dwSize member of the DEVICE_INFO structure pointed to by
pDeviceInfo is invalid.
di.dwSize = (uint)Marshal.S izeOf(typeof(De viceInfo));
return di;
}
}
DWORD GetDeviceInfo(
HANDLE hDevice,
PDEVICE_INFO pDeviceInfo
); 2 2780
Sure C# can handle it, but it takes some effort to define the structs
correctly in C#, that's why I prefer C++ (MC++) for this kind of native
interop.
However, here your problem is that both structures _DEVICE_INFO and
DeviceInfo do not match (they are different structs!).
Also, GetDeviceInfo is unknown to me, I guess you meant
BluetoothGetDev iceInfo which takes BLUETOOTH_DEVIC E_INFO as second
argument?
Here's the BLUETOOTH_DEVIC E_INFO struct definition:
[StructLayout(La youtKind.Sequen tial)]
struct BLUETOOTH_DEVIC E_INFO {
internal uint dwSize;
[MarshalAs(Unman agedType.ByValA rray, SizeConst=8)]
internal byte[] address;
uint ulClassofDevice ;
bool fConnected;
bool fRemembered;
bool fAuthenticated;
SystemTime stLastSeen;
SystemTime stLastUsed;
[MarshalAs(Unman agedType.ByValT Str, SizeConst = 248 )]
internal string szName;
internal ulong BTH_ADDR {
get {
return (ulong)address[5] + ((ulong)address[4] << 8)
+ ((ulong)address[3] << 16) + ((ulong)address[2] << 24)
+ ((ulong)address[1] << 32) + ((ulong)address[0] << 40);
}
}
}
[StructLayout(La youtKind.Sequen tial)]
public class SystemTime {
public ushort wYear;
public ushort wMonth;
public ushort wDayOfWeek;
public ushort wDay;
public ushort wHour;
public ushort wMinute;
public ushort wSecond;
public ushort wMilliseconds;
}
Willy.
"B Vidyadhar Joshi" <jo*****@knowle dgepointsolutio ns.com> wrote in message
news:OQ******** ******@tk2msftn gp13.phx.gbl... After trying out various methods, I couldn't get the below structure to work. I read on some forum that combining value to type and reference type in a [StructLayout(La youtKind.Explic it)] is not valid. And to implement a union struct, we need to use [StructLayout(La youtKind.Explic it)]. If I combine both the structures, the size of the structure rturned by Marshal.SizeOf( ) is wrong. Does someone has an answer? Or is C# not capable to handle this?
typedef ULONGLONG ADDR; typedef struct _ADDRESS { union { ADDR ullLong; BYTE rgBytes[ 6 ]; }; } ADDRESS_STRUCT;
typedef struct _DEVICE_INFO { DWORD dwSize; ADDR Address; ULONG ulClassofDevice ; BOOL fConnected; BOOL fRemembered; BOOL fAuthenticated; SYSTEMTIME stLastSeen; SYSTEMTIME stLastUsed; WCHAR szName[ MAX_NAME_SIZE ]; } DEVICE_INFO_STR UCT;
[StructLayout(La youtKind.Sequen tial)] internal struct DeviceInfo { internal uint dwSize; [MarshalAs(Unman agedType.ByValA rray, SizeConst=6)] internal byte[] address; [MarshalAs(Unman agedType.ByValT Str, SizeConst = 248)] internal string szName; internal uint ulClassofDevice ; internal ushort lmpSubversion; internal ushort manufacturer; internal ulong Addr { get { return (ulong)address[5] + ((ulong)address[4] << 8) + ((ulong)address[3] << 16) + ((ulong)address[2] << 24) + ((ulong)address[1] << 32) + ((ulong)address[0] << 40); } }
internal static DeviceInfo Create() { DeviceInfo di = new DeviceInfo(); di.address = new byte[] {34, 56, 56, 234, 12, 34}; //Returns a wrong size. //This error is returned by GetDeviceInfo function (ERROR_REVISION _MISMATCH) //The dwSize member of the DEVICE_INFO structure pointed to by pDeviceInfo is invalid. di.dwSize = (uint)Marshal.S izeOf(typeof(De viceInfo)); return di; } }
DWORD GetDeviceInfo( HANDLE hDevice, PDEVICE_INFO pDeviceInfo );
Hi Willy,
Thanks. I was able to get this working with help from Grapecity and your
previous replies.
B Vidyadhar Joshi.
"Willy Denoyette [MVP]" <wi************ *@pandora.be> wrote in message
news:e0******** ******@TK2MSFTN GP11.phx.gbl... Sure C# can handle it, but it takes some effort to define the structs correctly in C#, that's why I prefer C++ (MC++) for this kind of native interop. However, here your problem is that both structures _DEVICE_INFO and DeviceInfo do not match (they are different structs!). Also, GetDeviceInfo is unknown to me, I guess you meant BluetoothGetDev iceInfo which takes BLUETOOTH_DEVIC E_INFO as second argument?
Here's the BLUETOOTH_DEVIC E_INFO struct definition:
[StructLayout(La youtKind.Sequen tial)] struct BLUETOOTH_DEVIC E_INFO { internal uint dwSize; [MarshalAs(Unman agedType.ByValA rray, SizeConst=8)] internal byte[] address; uint ulClassofDevice ; bool fConnected; bool fRemembered; bool fAuthenticated; SystemTime stLastSeen; SystemTime stLastUsed; [MarshalAs(Unman agedType.ByValT Str, SizeConst = 248 )] internal string szName; internal ulong BTH_ADDR { get { return (ulong)address[5] + ((ulong)address[4] << 8) + ((ulong)address[3] << 16) + ((ulong)address[2] << 24) + ((ulong)address[1] << 32) + ((ulong)address[0] << 40); } } } [StructLayout(La youtKind.Sequen tial)] public class SystemTime { public ushort wYear; public ushort wMonth; public ushort wDayOfWeek; public ushort wDay; public ushort wHour; public ushort wMinute; public ushort wSecond; public ushort wMilliseconds; }
Willy. "B Vidyadhar Joshi" <jo*****@knowle dgepointsolutio ns.com> wrote in message news:OQ******** ******@tk2msftn gp13.phx.gbl... After trying out various methods, I couldn't get the below structure to work. I read on some forum that combining value to type and reference type in a [StructLayout(La youtKind.Explic it)] is not valid. And to implement a union struct, we need to use [StructLayout(La youtKind.Explic it)]. If I combine both the structures, the size of the structure rturned by Marshal.SizeOf( ) is wrong. Does someone has an answer? Or is C# not capable to handle this?
typedef ULONGLONG ADDR; typedef struct _ADDRESS { union { ADDR ullLong; BYTE rgBytes[ 6 ]; }; } ADDRESS_STRUCT;
typedef struct _DEVICE_INFO { DWORD dwSize; ADDR Address; ULONG ulClassofDevice ; BOOL fConnected; BOOL fRemembered; BOOL fAuthenticated; SYSTEMTIME stLastSeen; SYSTEMTIME stLastUsed; WCHAR szName[ MAX_NAME_SIZE ]; } DEVICE_INFO_STR UCT;
[StructLayout(La youtKind.Sequen tial)] internal struct DeviceInfo { internal uint dwSize; [MarshalAs(Unman agedType.ByValA rray, SizeConst=6)] internal byte[] address; [MarshalAs(Unman agedType.ByValT Str, SizeConst = 248)] internal string szName; internal uint ulClassofDevice ; internal ushort lmpSubversion; internal ushort manufacturer; internal ulong Addr { get { return (ulong)address[5] + ((ulong)address[4] << 8) + ((ulong)address[3] << 16) + ((ulong)address[2] << 24) + ((ulong)address[1] << 32) + ((ulong)address[0] << 40); } }
internal static DeviceInfo Create() { DeviceInfo di = new DeviceInfo(); di.address = new byte[] {34, 56, 56, 234, 12, 34}; //Returns a wrong size. //This error is returned by GetDeviceInfo function (ERROR_REVISION _MISMATCH) //The dwSize member of the DEVICE_INFO structure pointed to by pDeviceInfo is invalid. di.dwSize = (uint)Marshal.S izeOf(typeof(De viceInfo)); return di; } }
DWORD GetDeviceInfo( HANDLE hDevice, PDEVICE_INFO pDeviceInfo );
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: mike420 |
last post by:
In the context of LATEX, some Pythonista asked what the big
successes of Lisp were. I think there were at least three *big*
successes.
a. orbitz.com web site uses Lisp for algorithms, etc.
b. Yahoo store was originally written in Lisp.
c. Emacs
The issues with these will probably come up, so I might as well
mention them myself (which will also make this a more balanced
|
by: middletree |
last post by:
I had some text links at the top of all my pages (in one include file),
which worked just fine. But I was asked to make it so that people in a
certain department, (this is an Intranet app) would see a particular link
that nobody else would. You'd find their name by getting their network
logon. This worked fine on all my pages, but for some reason, on one page,
it gives me an error. First, the error:
Error Type:
ADODB.Recordset...
|
by: LP |
last post by:
I am using (trying to) CR version XI, cascading parameters feature works it
asks user to enter params. But if page is resubmitted. It prompts for params
again. I did set ReuseParameterValuesOnRefresh="True" in a viewer, but it
still doesn't work. Did anyone run into this problem. What's the solution?
Please help.
Thank you
|
by: J Rieggle |
last post by:
Hi,
Having been flamed for my previous HEEEELP! post and called childish, I
decided to reframe this problem - I have to have something ready for
tomorrow morning, and my server has stopped working and I have no clue how
to fix it, hence my original post, sent from a place of severe stress.
I rebooted my box for no particular reason other than I had decided to
reboot my router. When XP had sorted itself out, I loaded Dev Studio 2003...
|
by: Nalaka |
last post by:
Hi,
I suddenly started getting a lot of errors from html validation (some CSS)
so I followed the following instructions to disable it.
If you'd rather not have these types of HTML validation errors show up in
your error-list, you can disable this functionality by selecting the
Tools->Options menu item in VS or Visual Web Developer. Select the
TextEditor->Html->Validation tree option in the left-hand side of the
| |
by: Tony |
last post by:
I have a situation where I want to send data, but I have no need for a
response. It seems to me that XMLHTTPRequest is the best way to send the
data, but I don't need any response back from the server.
Basically, I'm writing js errors to an error log on the server side -
and there is no need to inform the user that the error has been logged.
The problem is that I don't want to sit with the request open & waiting
for a response, when I...
|
by: Frank |
last post by:
I've done this a few times.
In a solution I have a project, Say P1, and need another project that will
contain much code that is similar to that of P1.
I hope no one gets hung up on why I don't somehow share the code.
So, I copy the folder P1 is in, change the new folder name, and is VS2005 to
change all occurrences of P1's name tp P2's name.
|
by: oneski |
last post by:
help --- 403 You don't have permission
Im trying to get a basic search to work on my website, but i keep getting a forbidden error come up. Im using WAMP5 server on a vista machine. The error file from the apache side says:
(20024)The given path misformatted or contained invalid characters: Cannot map POST /test/%3C?=$PHP_SELF?%3E HTTP/1.1 to file, referer: http://localhost/test/searchscript.php
and this is the code im using.
...
|
by: Jan |
last post by:
Hi:
Here's a problem I've had for a long time. The client is really running
out of patience, and I have no answers.
Access2003, front- and back-end.
Single form with 4 subforms (each representing a related table), 5-10
clerks doing data entry at one time. Tables are quite large but all
work is done with unbound forms and/or local temp tables, and written
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |