hi,
I import a funtion fromm dll file:
dll function header :
DWORD WINAPI
Enumerate(
HANDLE hWDMHandle,
PNDIS_STATUS pNStatus,
PWCHAR pBuffer,
PUINT pBufferSize
)
in C# should be:
[DllImport("MyAPIdll", SetLastError=true)]
private static extern unsafe ulong Enumerate (
IntPtr g_hPCASIMHandle,
ulong* pNStatus,
void* pBuffer,
uint* pBufferSize);
und aufgerufen:
[CSHARP]
byte[] buf = new byte[2024];
uint iBytesRead = 0;
ulong ioResult;
ulong ndis_status;
uint buffsize;
unsafe
{
// create a void pointer to buf
fixed (void* pBuffer = buf)
{
ioResult=Enumerate(this.m_iHandle,
&ndis_status,pBuffer,&buffsize);
}
So how can i read buf or convert it to string ? 6 12847
"centrino" <ce******@discussions.microsoft.com> wrote in message
news:7E**********************************@microsof t.com... hi,
I import a funtion fromm dll file:
dll function header :
DWORD WINAPI Enumerate( HANDLE hWDMHandle, PNDIS_STATUS pNStatus, PWCHAR pBuffer, PUINT pBufferSize )
in C# should be:
[DllImport("MyAPIdll", SetLastError=true)] private static extern unsafe ulong Enumerate ( IntPtr g_hPCASIMHandle, ulong* pNStatus, void* pBuffer, uint* pBufferSize);
und aufgerufen:
[CSHARP] byte[] buf = new byte[2024]; uint iBytesRead = 0; ulong ioResult; ulong ndis_status; uint buffsize;
unsafe { // create a void pointer to buf fixed (void* pBuffer = buf) { ioResult=Enumerate(this.m_iHandle, &ndis_status,pBuffer,&buffsize); }
So how can i read buf or convert it to string ?
There is no need for this, but first some remarks.
1. A long in C# is a 64 bit entity in C it's 32 bit.
2. There is no need for unsafe in your declarations and your code.
3. strings in C# are w_char strings, PInvoke marshaling considers ANSI by
default, so you need to change this behavior.
Change your function declaration into:
[DllImport("MyAPIdll", SetLastError=true)]
private static extern uint Enumerate (
IntPtr g_hPCASIMHandle,
ref uint pNStatus,
[MarshalAs(UnmanagedType.LPWStr)]
StringBuilder pBuffer,
ref uint pBufferSize);
And use it as:
StringBuilder buf new StringBuilder( 2048);
uint iBytesRead = 0;
uintioResult;
uint ndis_status;
uint buffsize;
....
ioResult = Enumerate(this.m_iHandle, ref ndis_status, buf, ref buffsize);
string s = buf.ToString();
Willy.
"centrino" <ce******@discussions.microsoft.com> wrote in message
news:7E**********************************@microsof t.com... hi,
I import a funtion fromm dll file:
dll function header :
DWORD WINAPI Enumerate( HANDLE hWDMHandle, PNDIS_STATUS pNStatus, PWCHAR pBuffer, PUINT pBufferSize )
in C# should be:
[DllImport("MyAPIdll", SetLastError=true)] private static extern unsafe ulong Enumerate ( IntPtr g_hPCASIMHandle, ulong* pNStatus, void* pBuffer, uint* pBufferSize);
und aufgerufen:
[CSHARP] byte[] buf = new byte[2024]; uint iBytesRead = 0; ulong ioResult; ulong ndis_status; uint buffsize;
unsafe { // create a void pointer to buf fixed (void* pBuffer = buf) { ioResult=Enumerate(this.m_iHandle, &ndis_status,pBuffer,&buffsize); }
So how can i read buf or convert it to string ?
There is no need for this, but first some remarks.
1. A long in C# is a 64 bit entity in C it's 32 bit.
2. There is no need for unsafe in your declarations and your code.
3. strings in C# are w_char strings, PInvoke marshaling considers ANSI by
default, so you need to change this behavior.
Change your function declaration into:
[DllImport("MyAPIdll", SetLastError=true)]
private static extern uint Enumerate (
IntPtr g_hPCASIMHandle,
ref uint pNStatus,
[MarshalAs(UnmanagedType.LPWStr)]
StringBuilder pBuffer,
ref uint pBufferSize);
And use it as:
StringBuilder buf new StringBuilder( 2048);
uint iBytesRead = 0;
uintioResult;
uint ndis_status;
uint buffsize;
....
ioResult = Enumerate(this.m_iHandle, ref ndis_status, buf, ref buffsize);
string s = buf.ToString();
Willy.
Thanks Willy !
It works.
But i think i get only first vallue of pBuffer.
Maybe i need an array of;
StringBuilder[] buf;
How can i initializise it:
StringBuilder[] buf = new StringBuilder ....????
and:
[DllImport("MyAPIdll", SetLastError=true)]
private static extern uint Enumerate (
IntPtr g_hPCASIMHandle,
ref uint pNStatus,
[MarshalAs(UnmanagedType.LPWStr)]
StringBuilder pBuffer, // ???????
ref uint pBufferSize)
"Willy Denoyette [MVP]" wrote: "centrino" <ce******@discussions.microsoft.com> wrote in message news:7E**********************************@microsof t.com... hi,
I import a funtion fromm dll file:
dll function header :
DWORD WINAPI Enumerate( HANDLE hWDMHandle, PNDIS_STATUS pNStatus, PWCHAR pBuffer, PUINT pBufferSize )
in C# should be:
[DllImport("MyAPIdll", SetLastError=true)] private static extern unsafe ulong Enumerate ( IntPtr g_hPCASIMHandle, ulong* pNStatus, void* pBuffer, uint* pBufferSize);
und aufgerufen:
[CSHARP] byte[] buf = new byte[2024]; uint iBytesRead = 0; ulong ioResult; ulong ndis_status; uint buffsize;
unsafe { // create a void pointer to buf fixed (void* pBuffer = buf) { ioResult=Enumerate(this.m_iHandle, &ndis_status,pBuffer,&buffsize); }
So how can i read buf or convert it to string ?
There is no need for this, but first some remarks. 1. A long in C# is a 64 bit entity in C it's 32 bit. 2. There is no need for unsafe in your declarations and your code. 3. strings in C# are w_char strings, PInvoke marshaling considers ANSI by default, so you need to change this behavior.
Change your function declaration into:
[DllImport("MyAPIdll", SetLastError=true)] private static extern uint Enumerate ( IntPtr g_hPCASIMHandle, ref uint pNStatus, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder pBuffer, ref uint pBufferSize);
And use it as:
StringBuilder buf new StringBuilder( 2048); uint iBytesRead = 0; uintioResult; uint ndis_status; uint buffsize;
.... ioResult = Enumerate(this.m_iHandle, ref ndis_status, buf, ref buffsize); string s = buf.ToString();
Willy.
"centrino" <ce******@discussions.microsoft.com> wrote in message
news:27**********************************@microsof t.com... Thanks Willy ! It works. But i think i get only first vallue of pBuffer. Maybe i need an array of;
StringBuilder[] buf;
How can i initializise it: StringBuilder[] buf = new StringBuilder ....????
and:
[DllImport("MyAPIdll", SetLastError=true)] private static extern uint Enumerate ( IntPtr g_hPCASIMHandle, ref uint pNStatus, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder pBuffer, // ??????? ref uint pBufferSize)
No, you don't need a StringBuilder[].
What do you mean with the first value, do you mean the first character? How
are you looking at it, don't say in the debugger.
What is the length of the string in the StringBuilder?
int len = buf.ToString().Length;
Did you check the value in pBufferSize on return?
Willy.
i get:
pBufferSize: 772
pBuffer: \Device\{91E405CA-9D5E-4366-BB44-3B27E09C6C35}
i think i would get more, i don't know !?
regards
"Willy Denoyette [MVP]" wrote: "centrino" <ce******@discussions.microsoft.com> wrote in message news:27**********************************@microsof t.com... Thanks Willy ! It works. But i think i get only first vallue of pBuffer. Maybe i need an array of;
StringBuilder[] buf;
How can i initializise it: StringBuilder[] buf = new StringBuilder ....????
and:
[DllImport("MyAPIdll", SetLastError=true)] private static extern uint Enumerate ( IntPtr g_hPCASIMHandle, ref uint pNStatus, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder pBuffer, // ??????? ref uint pBufferSize)
No, you don't need a StringBuilder[]. What do you mean with the first value, do you mean the first character? How are you looking at it, don't say in the debugger.
What is the length of the string in the StringBuilder? int len = buf.ToString().Length;
Did you check the value in pBufferSize on return?
Willy.
"centrino" <ce******@discussions.microsoft.com> wrote in message
news:D9**********************************@microsof t.com... i get:
pBufferSize: 772 pBuffer: \Device\{91E405CA-9D5E-4366-BB44-3B27E09C6C35}
i think i would get more, i don't know !?
regards
I guess you do have more. Your pBufferSize is 772 ( don't know what exactly,
chars or bytes), the string is shorter anyway.
I guess the buffer returned contains strings delimitted with 'nulls', like
this...
\Device\{91E405CA-9D5E-4366-BB44-3B27E09C6C35}\0\0
\Device\{......................................... .................}\0\0
You can check the stringbuilders Length after return.
If I'm right, you can use ToString(int startindex, int length) to retrieve
the individual strings from the StringBuilders buffer.
Willy. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Dave Turner |
last post by:
Ive used fwrite to store 4 bytes in a file: "Test" (or 0x54657374 /
1953719636). Its easy enough to use fread to get those 4 bytes, but the
problem is I need to work with the data as a number and...
|
by: Swarup |
last post by:
I am reading a file (txt, xml, gif, ico, bmp etc) byte by byte and filling
it into a byte arry. Now i have to convert it into a string to store it in
the database.
I use...
|
by: FrzzMan |
last post by:
How to convert back a string that have converted to byte using
System.Text.Encoding.UTF8.GetBytes()
string StringData = "This is a string";
byte ConvertedString =...
|
by: Chris |
last post by:
Hi,
I try to print out truth-tables for an &&-operation using the following
code, unfortunatly I get compiler errors :
for ( byte i1=0; i1<=1; i1++)
{
for ( byte i2=0; i2<=1; i2++)
{
bool...
|
by: Ricardo Quintanilla |
last post by:
i have a code that sends data to a socket listening over as400 platform,
the socket responds to me as a "byte array".
then i need to convert the "byte array" into a string.
the problem is that...
|
by: Kueishiong Tu |
last post by:
How do I convert a Byte array (unsigned char managed) to a
char array(unmanaged) with wide character taken into
account?
|
by: centrino |
last post by:
hi,
I import a funtion fromm dll file:
dll function header :
DWORD WINAPI
Enumerate(
HANDLE hWDMHandle,
PNDIS_STATUS pNStatus,
|
by: Serge BRIC |
last post by:
My application, written in .NET VB, tries to get a communication port handle
from a TAPI object with this code:
Dim vFileHandle As Byte() = appel.GetIDAsVariant("comm/datamodem")
The...
|
by: Slippy27 |
last post by:
How do I test a byte string in Python? I want to manually convert (no libraries or functions) a UTF-8 string into UTF-16.
My basic solution is to read from the stream some number of UTF-8 bytes,...
|
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...
|
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,...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
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 ...
| |