Results 1 to 6 of 6

Thread: Convert this please [resolved]

  1. #1

    Thread Starter
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755

    Convert this please [resolved]

    Hi!

    Could anyone please help me convert this VB code to C++ code?

    VB Code:
    1. Private Type PointUDT
    2.     X As Double
    3.     Y As Double
    4.     Z As Double
    5. End Type


    I'm making a dll in C++ to speed up my VB program a bit, but i dont really know how to recieve UDT's from C++.....
    Last edited by cyborg; Mar 31st, 2004 at 10:35 PM.
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  2. #2
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629
    Syntax
    struct [<struct type name>] {

    [<type> <variable-name[, variable-name, ...]>] ;
    .
    .
    .

    } [<structure variables>] ;



    Example

    #include <string.h>

    struct my_struct {
    char name[80], phone_number[80];
    int age, height;
    } my_friend;

    void func() {
    strcpy(my_friend.name,"Mr. Wizard"); /* accessing an element */
    }

    struct my_struct my_friends[100]; /* declaring additional variables */

  3. #3

    Thread Starter
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    I'm still having problems...Here's my struct:

    Code:
    struct sPoint {
    	double X, Y, Z;
    };

    Here's the function in C++:
    Code:
    bool _stdcall CheckTriangle(sPoint A,sPoint B,sPoint C,double X,double Y)
    {
        if (Determinant(A.X, A.Y, B.X, B.Y, X, Y) && Determinant(B.X, B.Y, C.X, C.Y, X, Y) && Determinant(C.X, C.Y, A.X, A.Y, X, Y))
            return true;
    	else
            return false;
    }
    I don't have any problems compiling this code! It works fine.
    It's in VB the problem is.

    Here's the UDT in VB:
    VB Code:
    1. Private Type PointUDT
    2.     X As Double
    3.     Y As Double
    4.     Z As Double
    5. End Type

    Here's how i declare the function:
    VB Code:
    1. Private Declare Function CheckTriangle Lib "3d.dll" (ByRef A As PointUDT, ByRef B As PointUDT, ByRef C As PointUDT, ByVal X As Double, ByVal Y As Double) As Boolean

    VB gives me this error msg: "Bad DLL calling convention"
    What's wrong with this code?
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  4. #4
    Fanatic Member
    Join Date
    Dec 2003
    Posts
    703
    Your C function should take pointers to sPoint structs:

    bool _stdcall CheckTriangle(sPoint* A,sPoint* B,sPoint* C,double X,double Y)

    Also, when doing C dlls for VB i always use a def file to export the functions, are you doing that?
    an ending

  5. #5
    Frenzied Member dis1411's Avatar
    Join Date
    Mar 2001
    Posts
    1,048
    just a thought, try this post and see if it helps

    http://www.vbforums.com/showthread.php?threadid=260063

  6. #6

    Thread Starter
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    Originally posted by azteched
    Your C function should take pointers to sPoint structs:
    Thanks alot! Works perfect now!
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

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