|
-
Jul 19th, 2007, 07:51 AM
#1
[RESOLVED] Question about C structure
Ok, to start... I am very unfamiliar with c and c++. I have a simple app written in C and I am trying to convert it to vb.net. I am just wondering about a structure that is in the file. this is the structure.
Code:
struct Packet {
int size;
int (*realFunc)(void *, void *, void *, unsigned char *, int, void *);
unsigned int repeat;
unsigned char buf[2048];
};
I can convert it for the most part, but that function (if that is what it is) confuses me.
This is what I have so far
Code:
Private Structure Packet
Dim size As Integer
Public Function realFunc(ByVal val1 As Object, ByVal val2 As Object, _
ByVal val3 As Object, ByVal SomeByte As Byte, ByVal Size As Integer, _
ByVal val4 As Object) As Integer
'I defined them as just objects for lack
'of an understanding of what they are
End Function
Dim Repeat As UInt32
Dim buf() As Byte
End Structure
What I am wondering about is the realFunc variable. Is this a function within a structure? also what does void * mean. I was under the assumption tha void was similar to declaring a sub in vb so, this really confuses me. Thanks to anyone that can help
B
Last edited by bmahler; Jul 19th, 2007 at 07:56 AM.
-
Jul 19th, 2007, 07:57 AM
#2
Re: Question about C structure
If I remember correctly, that is a pointer to a function realFunc accepting those parameters.
void* is a void pointer, which means that it can accept any type of pointer as a parameter. Example you can pass an int*, or float* or char* or a Packet* (yes, pointer of your structure) as first parameter.
Again said, I could be wrong. Need to brush up everything now!!!
-
Jul 20th, 2007, 12:05 AM
#3
Re: Question about C structure
Yes, that is a pointer to a function, and yes, void pointers can point to an object of any type.
VB6 had the option of an "Any" type.. I'm not sure if .NET does.. give it a shot? (Dim variable As Any).
Are you just copying the data type? Or is this type actually going to be sent into your program from another source? If the latter, forget about using VB. Theres no way to overcome that obstacle.
If you're just copying the type, then the best you'll get is writing your own function for "realFunc" that always accepts the same parameters (not void objects.. which may not be available in VB.NET).
chem
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Jul 20th, 2007, 02:15 PM
#4
Re: Question about C structure
Ya, any is not allowed in .net. I am just trying to rewrite a simple C console app in .net and that structure was giving me a headache. Thanks for your help guys.
-
Jul 23rd, 2007, 06:22 AM
#5
Re: [RESOLVED] Question about C structure
If you need to convert this:
Code:
int (*realFunc)(void *, void *, void *, unsigned char *, int, void *);
Then it might be worth investigating delegates. As for the void* arguments, you can call in IntPtr objects. All depemds how accurately you want to simulate the original functionality.
-
Jul 25th, 2007, 07:43 AM
#6
Re: [RESOLVED] Question about C structure
well, I decided against rewriting it and instead took the C console app I had and just made a dll out of the code. Thanks again for your help.
-
Jul 26th, 2007, 01:42 PM
#7
Re: [RESOLVED] Question about C structure
Just in case anyone's interested, here the equivalent VB code (via C++ to VB Converter):
Code:
Public Class Packet
Public size As Integer
Public Delegate Function realFuncDelegate(ByVal UnnamedParameter1 As IntPtr, ByVal UnnamedParameter2 As IntPtr, ByVal UnnamedParameter3 As IntPtr, ByVal UnnamedParameter4 As Byte, ByVal UnnamedParameter5 As Integer, ByVal UnnamedParameter6 As IntPtr) As Integer
Public realFunc As realFuncDelegate
Public repeat As UInteger
Public buf As Byte() = New Byte(2047){}
End Class
A couple of notes:
1. The C++ struct equates to a VB Class, not a Structure. (The C++ struct is nearly identical to the C++ class, except the default access is public).
2. Array size in VB is set by specifying upper bound, not length.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|