473,657 Members | 2,595 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

char[4] data type in c for storing IPs - VB.NET equivalence

Hi everyone:
i read from the documentation of a dll that there is a struct that uses
char[4] for storing an IP address. How can it be? and how come i can get to
representate the same value in a string VB.NET data type, knowing that this
is its equivalence (for char4)?
Next is the data type definition
'''unsigned char[4]

<System.Runtime .InteropService s.MarshalAsAttr ibute(System.Ru ntime.InteropSe rvices.Unmanage dType.ByValTStr , SizeConst:=4)_

Public IP As String

Thanks very much for your help!
--
Emilio Javier Leyes
Técnico Universitario en Informática
Sistema de Emergencias 911
Salta, Argentina
Aug 12 '08 #1
20 2811
'unsigned char' is Byte in VB.
As an example, the equivalent to the following C++:
unsigned char test[4];
is:
Dim test(3) As Byte
--
http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
VB & C# to Java
Java to VB & C#
Instant C#: VB to C#
Instant VB: C# to VB
Instant C++: VB, C#, or Java to C++/CLI
"emitojleye s" wrote:
Hi everyone:
i read from the documentation of a dll that there is a struct that uses
char[4] for storing an IP address. How can it be? and how come i can get to
representate the same value in a string VB.NET data type, knowing that this
is its equivalence (for char4)?
Next is the data type definition
'''unsigned char[4]

<System.Runtime .InteropService s.MarshalAsAttr ibute(System.Ru ntime.InteropSe rvices.Unmanage dType.ByValTStr , SizeConst:=4)_

Public IP As String

Thanks very much for your help!
--
Emilio Javier Leyes
Técnico Universitario en Informática
Sistema de Emergencias 911
Salta, Argentina
Aug 13 '08 #2
Hi david, and thanks very muuch for your reply.
What i worte in vb.net, actually i didn't do it. I used an application
avaiable in
http://blogs.msdn.com/vbteam/archive...voke-easy.aspx,
that apparently helped me a lot, because, before this problem, i was getting
an error and couldn't find the solution.
Now, you say the data type must be byte... so, what value should i write for
the following ip address, for example: 192.168.010.008 ?
I tried replacing string for byte in:
<System.Runtime .InteropService s.MarshalAsAttr ibute(System.Ru ntime.InteropSe rvices.Unmanage dType.ByValTStr , SizeConst:=4)>, but i got an error...
How can i continue? Thanks again david.
--
Emilio Javier Leyes
Técnico Universitario en Informática
Sistema de Emergencias 911
Salta, Argentina
"David Anton" wrote:
'unsigned char' is Byte in VB.
As an example, the equivalent to the following C++:
unsigned char test[4];
is:
Dim test(3) As Byte
--
http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
VB & C# to Java
Java to VB & C#
Instant C#: VB to C#
Instant VB: C# to VB
Instant C++: VB, C#, or Java to C++/CLI
"emitojleye s" wrote:
Hi everyone:
i read from the documentation of a dll that there is a struct that uses
char[4] for storing an IP address. How can it be? and how come i can get to
representate the same value in a string VB.NET data type, knowing that this
is its equivalence (for char4)?
Next is the data type definition
'''unsigned char[4]
<System.Runtime .InteropService s.MarshalAsAttr ibute(System.Ru ntime.InteropSe rvices.Unmanage dType.ByValTStr , SizeConst:=4)_

Public IP As String

Thanks very much for your help!
--
Emilio Javier Leyes
Técnico Universitario en Informática
Sistema de Emergencias 911
Salta, Argentina
Aug 13 '08 #3
emitojleyes wrote:
Hi david, and thanks very muuch for your reply.
What i worte in vb.net, actually i didn't do it. I used an application
avaiable in
http://blogs.msdn.com/vbteam/archive...voke-easy.aspx,
that apparently helped me a lot, because, before this problem, i was getting
an error and couldn't find the solution.
Now, you say the data type must be byte... so, what value should i write for
the following ip address, for example: 192.168.010.008 ?
New Byte() { 192, 168, 10, 8 }
I tried replacing string for byte in:
<System.Runtime .InteropService s.MarshalAsAttr ibute(System.Ru ntime.InteropSe rvices.Unmanage dType.ByValTStr , SizeConst:=4)>, but i got an error...
How can i continue? Thanks again david.
You want a byte array with the size 4, so it should be something like:

<MarshalAsAttri bute(UnmanagedT ype.LPArray, SizeConst:=4,
ArraySubType:=U nmanagedType.U1 >

--
Göran Andersson
_____
http://www.guffa.com
Aug 13 '08 #4
"Göran Andersson" <gu***@guffa.co mschrieb:
>Hi david, and thanks very muuch for your reply.
What i worte in vb.net, actually i didn't do it. I used an application
avaiable in
http://blogs.msdn.com/vbteam/archive...voke-easy.aspx,
that apparently helped me a lot, because, before this problem, i was
getting an error and couldn't find the solution.
Now, you say the data type must be byte... so, what value should i write
for the following ip address, for example: 192.168.010.008 ?

New Byte() { 192, 168, 10, 8 }
>I tried replacing string for byte in:
<System.Runtim e.InteropServic es.MarshalAsAtt ribute(System.R untime.InteropS ervices.Unmanag edType.ByValTSt r,
SizeConst:=4)> , but i got an error...
How can i continue? Thanks again david.

You want a byte array with the size 4, so it should be something like:

<MarshalAsAttri bute(UnmanagedT ype.LPArray, SizeConst:=4,
ArraySubType:=U nmanagedType.U1 >
Maybe 'ByValArray' is more suitable as 'LPArray' is not used to store the
array elements inside the structure.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Aug 13 '08 #5
Thanks very much for the suggestions!
I'll be trying it tomorrow, and let you know, so, PLEASE don't lose track of
this thread.
Thanks again!

--
Emilio Javier Leyes
Técnico Universitario en Informática
Sistema de Emergencias 911
Salta, Argentina
Aug 13 '08 #6
As an alternative, I would suggest using an Int32 as that gives you the four
bytes. You can also use a struct or do explicit layout so as you have a
union of an Int32 and four bytes, e.g:
Structure IPAddress
Public a As Byte
Public b As Byte
Public c As Byte
Public d As Byte
End Structure
Or:

<StructLayout(L ayoutKind.Expli cit)_
Structure IPAddress
<FieldOffset(0) Public a As Byte
<FieldOffset(1) Public b As Byte
<FieldOffset(2) Public c As Byte
<FieldOffset(3) Public d As Byte

<FieldOffset(0) Public value As Int32

Public Overrides Function ToString() As String
Return String.Format(" {0}.{1}.{2}.{3} ", a, b, c, d)
End Function
End Structure


"emitojleye s" <em*********@di scussions.micro soft.comwrote in message
news:73******** *************** ***********@mic rosoft.com...
Thanks very much for the suggestions!
I'll be trying it tomorrow, and let you know, so, PLEASE don't lose track
of
this thread.
Thanks again!

--
Emilio Javier Leyes
Técnico Universitario en Informática
Sistema de Emergencias 911
Salta, Argentina
Aug 14 '08 #7
Hi everyone:
The problem is still there... i cannot solve it.
Goran, i have used the data type you suggest me:
<System.Runtime .InteropService s.MarshalAsAttr ibute(System.Ru ntime.InteropSe rvices.Unmanage dType.ByValArra y, SizeConst:=4)_
Public IP As Byte()
and assigned the values:
.IP = New Byte() {192, 168, 10, 8}
But it didn't work.
And still didn't try what bill told me to do, because i don't understand
much how to do it...
As this issue is beating me, i have taken extremes measures. Below are the
links to download the dlls flies, the advanced spectifications document, and
the user manual, i will really appreciate you look the technical specs doc,
becaouse maybe i'm having a mistake in other issue that you could notice
better than me.

Also i tried as Herfried told me:

<System.Runtime .InteropService s.MarshalAsAttr ibute(System.Ru ntime.InteropSe rvices.Unmanage dType.ByValArra y,
SizeConst:=4, ArraySubType:=S ystem.Runtime.I nteropServices. UnmanagedType.U 1)>
_
Public IP As Byte()
but didn't work either.
Advanced Specifications document:
http://www.fundesnoa.org.ar/wison/Ad...or_Spec_02.pdf

WisClient library DLL:
http://www.fundesnoa.org.ar/wison/WisClient.dll

WisServer library DLL:
http://www.fundesnoa.org.ar/wison/WisServer.dll

User Manual:
http://www.fundesnoa.org.ar/wison/DR168_Eng.pdf

Thanks very much in advance, for any comments about this issue.
Best regards,
--
Emilio Javier Leyes
Técnico Universitario en Informática
Sistema de Emergencias 911
Salta, Argentina
Aug 14 '08 #8
Hi emitojleyes,

Define the structure as I showed (either one), e.g:
<StructLayout(L ayoutKind.Expli cit)_
Structure IPAddress
<FieldOffset(0) Public a As Byte
<FieldOffset(1) Public b As Byte
<FieldOffset(2) Public c As Byte
<FieldOffset(3) Public d As Byte

<FieldOffset(0) Public value As Int32

Public Overrides Function ToString() As String
Return String.Format(" {0}.{1}.{2}.{3} ", a, b, c, d)
End Function
End Structure
Then declare the field or parameter as Byval ip As IPAddress


"emitojleye s" <em*********@di scussions.micro soft.comwrote in message
news:1E******** *************** ***********@mic rosoft.com...
Hi everyone:
The problem is still there... i cannot solve it.
Goran, i have used the data type you suggest me:
<System.Runtime .InteropService s.MarshalAsAttr ibute(System.Ru ntime.InteropSe rvices.Unmanage dType.ByValArra y,
SizeConst:=4)_
Public IP As Byte()
and assigned the values:
.IP = New Byte() {192, 168, 10, 8}
But it didn't work.
And still didn't try what bill told me to do, because i don't understand
much how to do it...
As this issue is beating me, i have taken extremes measures. Below are the
links to download the dlls flies, the advanced spectifications document,
and
the user manual, i will really appreciate you look the technical specs
doc,
becaouse maybe i'm having a mistake in other issue that you could notice
better than me.

Also i tried as Herfried told me:

<System.Runtime .InteropService s.MarshalAsAttr ibute(System.Ru ntime.InteropSe rvices.Unmanage dType.ByValArra y,
SizeConst:=4,
ArraySubType:=S ystem.Runtime.I nteropServices. UnmanagedType.U 1)>
_
Public IP As Byte()
but didn't work either.
Advanced Specifications document:
http://www.fundesnoa.org.ar/wison/Ad...or_Spec_02.pdf

WisClient library DLL:
http://www.fundesnoa.org.ar/wison/WisClient.dll

WisServer library DLL:
http://www.fundesnoa.org.ar/wison/WisServer.dll

User Manual:
http://www.fundesnoa.org.ar/wison/DR168_Eng.pdf

Thanks very much in advance, for any comments about this issue.
Best regards,
--
Emilio Javier Leyes
Técnico Universitario en Informática
Sistema de Emergencias 911
Salta, Argentina

Aug 14 '08 #9

I've tried what you Bill told me, but still doesn't work...
i think it's not a big problem to slve this issue, but i am a real beginner
at this, and don't know where else to continue looking for the solution.
That's why i put the links for downloading the documentation of this device.
I hope you take a look at them and understand the problem, and realise it's
not big deal... or is it?
Next, i'll put the source code of the windows form where it is the button
that TESTS the device. All the data definition was made automatically by this
program i mentioned before, with the exception of the last attemps i made,
modifying the IP member of systemdata, following Bill's advice.
I am really thankful for all the help i got from this forum, and hope to get
to solve it; without your help... it'd be really impossible for me.

---------------
Public Class Form1

<System.Runtime .InteropService s.StructLayoutA ttribute(System .Runtime.Intero pServices.Layou tKind.Sequentia l,
CharSet:=System .Runtime.Intero pServices.CharS et.[Ansi])_
Public Structure SYSTEMDATA

'''unsigned char
Public Version As Byte
<System.Runtime .InteropService s.StructLayout( System.Runtime. InteropServices .LayoutKind.Exp licit)_
Structure IPAddress
<System.Runtime .InteropService s.FieldOffset(0 )Public a As Byte
<System.Runtime .InteropService s.FieldOffset(1 )Public b As Byte
<System.Runtime .InteropService s.FieldOffset(2 )Public c As Byte
<System.Runtime .InteropService s.FieldOffset(3 )Public d As Byte
<System.Runtime .InteropService s.FieldOffset(0 )Public value As
Int32

Public Overrides Function ToString() As String
Return String.Format(" {0}.{1}.{2}.{3} ", a, b, c, d)
End Function
End Structure

<System.Runtime .InteropService s.MarshalAsAttr ibute(System.Ru ntime.InteropSe rvices.Unmanage dType.Struct,
SizeConst:=4, ArraySubType:=S ystem.Runtime.I nteropServices. UnmanagedType.U 1)>
_
Public IP As IPAddress

'''unsigned char[4]

<System.Runtime .InteropService s.MarshalAsAttr ibute(System.Ru ntime.InteropSe rvices.Unmanage dType.ByValTStr , SizeConst:=4)_
Public NetMask As String

'''unsigned char[4]

<System.Runtime .InteropService s.MarshalAsAttr ibute(System.Ru ntime.InteropSe rvices.Unmanage dType.ByValTStr , SizeConst:=4)_
Public Gateway As String

'''unsigned char
Public BaudRate As Byte

'''unsigned char[3]

<System.Runtime .InteropService s.MarshalAsAttr ibute(System.Ru ntime.InteropSe rvices.Unmanage dType.ByValArra y, SizeConst:=3)_
Public DeviceID As Byte()

'''unsigned short
Public UserNo As UShort

'''unsigned int
Public LogNo As UInteger

'''unsigned char
Public AuthenMode As Byte

'''unsigned char
Public UartMode As Byte

'''unsigned char
Public VoiceEN As Byte

'''unsigned char[12]

<System.Runtime .InteropService s.MarshalAsAttr ibute(System.Ru ntime.InteropSe rvices.Unmanage dType.ByValTStr , SizeConst:=12)_
Public ServerIP As String

'''unsigned char
Public IDLength As Byte

'''unsigned char[20]
'''

<System.Runtime .InteropService s.MarshalAsAttr ibute(System.Ru ntime.InteropSe rvices.Unmanage dType.ByValTStr , SizeConst:=20)_
Public Reserved As String

'''DOORDATA->_DOORDATA
Public DoorData As DOORDATA

'''unsigned char[16]

<System.Runtime .InteropService s.MarshalAsAttr ibute(System.Ru ntime.InteropSe rvices.Unmanage dType.ByValTStr , SizeConst:=16)_
Public DeviceName As String

'''unsigned char
Public HasDevice As Byte

'''unsigned char
Public ProtocolPswd As Byte

'''unsigned char[7]

<System.Runtime .InteropService s.MarshalAsAttr ibute(System.Ru ntime.InteropSe rvices.Unmanage dType.ByValTStr , SizeConst:=7)_
Public Reserved1 As String
End Structure
<System.Runtime .InteropService s.StructLayoutA ttribute(System .Runtime.Intero pServices.Layou tKind.Sequentia l,
CharSet:=System .Runtime.Intero pServices.CharS et.[Ansi])_
Public Structure DOORDATA

'''unsigned short
Public DoorOpenSec As UShort

'''unsigned short
Public DoorOverSec As UShort

'''unsigned short
Public AlarmTime As UShort

'''unsigned char
Public AlarmEnable As Byte

'''unsigned char[9]

<System.Runtime .InteropService s.MarshalAsAttr ibute(System.Ru ntime.InteropSe rvices.Unmanage dType.ByValTStr , SizeConst:=9)_
Public Reserved As String
End Structure

Partial Public Class NativeMethods

'''Return Type: int
'''pwd: unsigned char*
'''CurSystemDat a: SYSTEMDATA->_SYSTEMDATA
<System.Runtime .InteropService s.DllImportAttr ibute("WisClien t.dll",
EntryPoint:="Wi s_Diagnose")_
Public Shared Function Wis_Diagnose(By Val pwd As System.IntPtr,
ByVal CurSystemData As SYSTEMDATA) As Integer
End Function
End Class

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim systemdata1 As New Form1.SYSTEMDAT A
Dim doordata1 As New Form1.DOORDATA
Dim a As System.IntPtr
With systemdata1
.ProtocolPswd = "00000000"
.IP.a = 192
.IP.b = 168
.IP.c = 10
.IP.d = 8
.NetMask = "255.255.25 5.0"
.ServerIP = "192.168.10 .4"
.Reserved = "00000000"
.Reserved1 = "00000000"
.DeviceID = New Byte() {0, 0, 0}
.Gateway = "192.168.10 .1"
.IDLength = 3
.HasDevice = 3
.DoorData.Reser ved = "00000000"

End With

a = "00000000"
MsgBox(NativeMe thods.Wis_Diagn ose(0, systemdata1))

End Sub
End Class
---------------

For those who want to see the documentation and download the DLL i cant make
work, the links are below.

Best regards,
Emilio Javier Leyes
Técnico Universitario en Informática
Sistema de Emergencias 911
Salta, Argentina

Advanced Specifications document:
http://www.fundesnoa.org.ar/wison/Ad...or_Spec_02.pdf

WisClient library DLL:
http://www.fundesnoa.org.ar/wison/WisClient.dll

WisServer library DLL:
http://www.fundesnoa.org.ar/wison/WisServer.dll

User Manual:
http://www.fundesnoa.org.ar/wison/DR168_Eng.pdf
Aug 15 '08 #10

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

Similar topics

4
2541
by: David Garamond | last post by:
Is it the 4+N (aka. same as VARCHAR(n)) or is it N? Sorry, it was 100% not clear for me after reading the docs, though the docs imply the first: "The storage requirement for data of these types is 4 bytes plus the actual string, and in case of character plus the padding." As a comparison, MySQL seems to do storage saving for fixed-length character (it doesn't store the length of the string). -- dave
11
11913
by: aruna | last post by:
How is a character stored in a word aligned machine? Assuming on 64bit machine, 1 byte is reserved for a char, is it the case that only 1 byte is used to store the character and the rest 7 bytes are wasted, or my assumption is wrong? If my assumption is right, what are the performance issues in retrieving value of a character variable over other data types like integer, double or float.
7
5580
by: techno | last post by:
Dear all, Our bitmap has some x00 values ( '\0' ) and i am storing it in char* array. the problem is that the '\0' is treated as eos character in c and it is truncating it so the characters after it are not pass to the function. here is the code snippet /* DATA8583.data = ( char ) ( unsigned int ) 0xF0;
10
5330
by: fei.liu | last post by:
Consider the following sample code char * ptr = "hello"; char carray = "hello"; int main(void){ } What does the standard have to say about the storage requirement about ptr and carray? Is it a fair statement that char *ptr will take 4 more bytes (on 32bit platform) in DATA segment? I have found
42
7370
by: sarathy | last post by:
Hi, I need clarification regarding signed characters in the C language. In C, char is 1 byte. So 1. Unsigned char - ASCII CHARACTER SET - EXTENDED CHARACTER SET
18
10402
by: planetzoom | last post by:
Given the following code: #include <stdio.h> int main(void) { char array = "What is your favorite car?"; void *vp = &array; printf("%s\n", vp);
6
4823
by: Ws | last post by:
Ok, so I have a question reguarding compilers and placing strings into the .rdata section of the PE. I was working on a program and couldn't figure out why I was getting a 0xc0000005 error message (memory access violation) while trying to alter a (char *) data type'd variable. Proper size, pointers all accurate and verified. I finally got frustrated enough and tried something else, built it as a Release application (using Microsoft...
11
2938
by: john | last post by:
Hi, at first the code doesn't seem to work. Any ideas?: #include <iostream> #include <cstdlib> int main() { using namespace std;
12
1774
by: s0suk3 | last post by:
I've seen a lot of functions in the standard library that deal with characters, but a lot them return/take parameters of type int (which is usually the integer that represents the character code in the character set). I know that C automatically converts between int and char in those cases without problems (or could the singed/unsigned issue cause problems?), and that character constants have actually type int, but, what is the reason for...
0
8392
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
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,...
0
8823
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8503
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7321
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, 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...
1
6163
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4151
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...
0
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.