Help me: Convert C++ to PB. Thanks for help <3

Just starting out? Need help? Post your questions and find answers here.
ilovepb
New User
New User
Posts: 2
Joined: Sat Oct 09, 2021 3:05 pm

Help me: Convert C++ to PB. Thanks for help <3

Post by ilovepb »

Hello,

I have a problem with translate a C++ code to PB.
My translation shows like this:

Original C++ *.h:

Code: Select all

typedef void (CALLBACK TStatusCallback)(double Progress, int StatusType, void *User);

typedef struct {
	BOOL MultipleMatches;
	BOOL MultiThreadedProcessing;
	int MultiThreadCount;
	TStatusCallback *StatusCallback;
} *PProcessParameters, TProcessParameters;

typedef struct {
	int Difference;
	float MatchPercentage;
} *PResultMatches, TResultMatches;

typedef struct {
	BOOL Success;
	int MatchCount;
	PResultMatches Matches;
} *PResult, TResult;

typedef int(LIBCALL *Text_Compare)(TProcessParameters Parameters, TResult *CompareResult, void *User);
And my PB code:

Code: Select all

Prototype TStatusCallback(Progress.d, StatusType.i, *User);
Structure TProcessParameters
    MultipleMatches.b
    MultiThreadedProcessing.b
    MultiThreadCount.i
    *StatusCallback.TStatusCallback
EndStructure

Structure TResultMatches
    Difference.i
    MatchPercentage.f
EndStructure

Structure TResult
    Success.b
    MatchCount.i
    Matches.TResultMatches
EndStructure

Prototype Text_Compare(Parameters, *CompareResult, *User)
Global Text_Compare.Text_Compare= GetFunction(hDLL, "Text_Compare")

Procedure StatusCallback(Progress.d, StatusType.i, *User)    
EndProcedure    

Parameters\MultipleMatches = #true
Parameters\StatusCallback = @StatusCallback( )
CompareResult.TResult

Text_Compare(Parameters, @CompareResult, @User)

I hope you can help me.
Thanks :oops:
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: Help me: Convert C++ to PB. Thanks for help <3

Post by Mijikai »

Probably:

Code: Select all

;int -> .l

Structure TProcessParameters
    MultipleMatches.b
    MultiThreadedProcessing.b
    MultiThreadCount.l
    *StatusCallback.TStatusCallback
EndStructure

Structure TResultMatches
    Difference.l
    MatchPercentage.f
EndStructure

Structure TResult
    Success.b
    MatchCount.l
    Matches.TResultMatches
EndStructure
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Help me: Convert C++ to PB. Thanks for help <3

Post by skywalk »

Are you sure Bool = byte?
Always compare sizeof(struct) in both languages.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Olli
Addict
Addict
Posts: 1071
Joined: Wed May 27, 2020 12:26 pm

Re: Help me: Convert C++ to PB. Thanks for help <3

Post by Olli »

A break we'll have on the forum is to search a message referring to C or C++. Even 'cpp' is too short to be used in retrieving of a subject about C++. It stays 'backend', term which recently appeared in the forum on the version 6. But this types conversion has already been discussed.

New cpp backend variables types conversion :
(C type : purebasic type (purebasic type symbol) )

unsigned char : type ascii (A)
char : type byte (B)
enum or
short int : word (W)
unsigned int or
int: unicode (U)
unsigned long : disabled on PureBasic
long : long (L)
float : float (F)
double : double (D)
long double (80 bits floating point value) : disabled on PureBasic
long long : quad (Q)

bool is as an unsigned long on cpp, so theorically unabled on x86/x64.
But just ignore the sign bit and connvert it as a purebasic integer (purebasic Long on x86, and purebasic Quad on X64).

bool : integer (I)
Post Reply