Results 1 to 7 of 7

Thread: [RESOLVED] Question about C structure

  1. #1

    Thread Starter
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Resolved [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.
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  2. #2
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    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!!!
    Show Appreciation. Rate Posts.

  3. #3
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    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

  4. #4

    Thread Starter
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    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.
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  5. #5
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    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.

  6. #6

    Thread Starter
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    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.
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  7. #7
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    710

    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.
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width