• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

My first steps with C++

Started by Patrice Terrier, July 30, 2010, 10:01:29 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Jürgen Huhn

#30
QuoteI have learned also how to use the #include directive:

   * #include <windows.h> // With <>, search along the path.
   * #include "WinLIFT.h"  // With "", search in the same directory of the current file.

Patrice,

thank you for sharing your Experiences. Thank`s for this include syntax!!
I want to give you a feedback for your Information that there is anyone who listen and want to learn.
Then i remember to another topic where do you told me that no one listen and we are alone, you and me..
But when i look on the Count how many user read the Thread then i think sometimes about over thousand user`s and
no one reply. Only a Hand full nice People who say`s thank`s. We know them, there`re always the same.
Sometimes the posts not really needed, to much or not by the topic, but you have a face of them.
Personally i get nearly every Day nice eMails with Question`s and many thank`s to me.
Today for example, from Gary Beene and Chris Boss for to have inspired Chris enough to give OpenGL a try with PB.

Back to the topic, because i really read your tranlations. For clarity or levelheadedness i need to
correct one of your statements especial for beginners in programming general or i need to revise my knowlege.

QuoteHere is an example of header translation:

I think is a mix of headers an Functions.. It`s ok because the Header`s are defined before the Function`s use them.
The Headers are the Definitition`s of Constants, Datatypes and Com Objects or GUID`s.

Like this in your translation:

#include <windows.h>
//
#include <iostream>
#include <string.h>

Your own definition`s:

#define WM_SKGETMENUICON (WM_USER + WM_GETICON)

// Anchor constants
#define ANCHOR_NONE                0
#define ANCHOR_LEFT                ANCHOR_NONE
#define ANCHOR_WIDTH               1
#define ANCHOR_RIGHT               2
#define ANCHOR_CENTER_HORZ         3
#define ANCHOR_HEIGHT              4
#define ANCHOR_HEIGHT_WIDTH        5
#define ANCHOR_HEIGHT_RIGHT        6
#define ANCHOR_BOTTOM              7
#define ANCHOR_BOTTOM_WIDTH        8
#define ANCHOR_BOTTOM_RIGHT        9
#define ANCHOR_CENTER_HORZ_BOTTOM  10
#define ANCHOR_CENTER_VERT         11
#define ANCHOR_CENTER_VERT_RIGHT   12
#define ANCHOR_CENTER              13

And this is a Function:

// Disable skinning of a specific control
int skSkinDisable(HWND hCtrl) {
   int nRet = 0;

   if (g_hWLFTdll) {
       typedef int (__stdcall *skProc) (HWND);
       skProc hPROC = (skProc) GetProcAddress(g_hWLFTdll, "skSkinDisable");
       if (hPROC) {
           nRet = hPROC(hCtrl);
       }
   }
   return nRet;
}

Or is it wrong??

The translation is good!! Ich könnte das nicht besser machen...

I`m also not an Expert for C/C++, but i use the Compilers which enjoys all the advantages about years.
You`re not so near at the Code like in Powerbasic.. You have a UserInterface(Visual), wich generating, translating,
dissasemle and debuging the Code build on Classes with a large Pool of Tools and so on ..
You don`t need to take a look into the Code, if you`re only work in a Visual Studios.

Do you think i missunderstood something?

And do you have the Debugging allways switched on for every running Program at any time your Computer is on?

I had also another Question, but forgot it over this.. :-X later..

All  my Best,

Jürgen  :)  :)
.¸.•'´¯)¸.•'´¯)¸.•'´¯)¸.•'´¯)
¤ª"˜¨¨¯¯¨¨˜"ª¤....¤ ª"˜¨

Patrice Terrier

#31
Jürgen,

Thanks for the feedback.

You wrote:
QuoteAnd this is a Function:

// Disable skinning of a specific control
int skSkinDisable(HWND hCtrl) {
  int nRet = 0;

   if (g_hWLFTdll) {
       typedef int (__stdcall *skProc) (HWND);
       skProc hPROC = (skProc) GetProcAddress(g_hWLFTdll, "skSkinDisable");
       if (hPROC) {
           nRet = hPROC(hCtrl);
       }
   }
   return nRet;
}

I would rather say: it is the "explicit" C++ counterpart declaration for this WinLIFT API PB's declaration:
Quote' Disable skinning of a specific control
 DECLARE FUNCTION skSkinDisable LIB "WinLIFT.dll" ALIAS "skSkinDisable" ( _
 BYVAL hCtrl AS LONG _              ' Handle of the child control to disable.
 ) AS LONG

Thus for me this C++ "WinLIFT.h" header, is to serve the same purpose that the PB's "WinLIFT.inc" include file.

I did it this way, because i was unable to use "implicit" linking with my PBwin32 DLL.

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Jürgen Huhn

Of course Patrice,

and for your Code i`ll be sure on the best Place!
But it`s technical a Function with an input and an output Value. Did you don`t ask your self,
maybe there is behind the DECLARE statement of Powerbasic the same??
Even only such a Function..   

We have the Procadress of the Library, the intput and the output definition as Types ???


.¸.•'´¯)¸.•'´¯)¸.•'´¯)¸.•'´¯)
¤ª"˜¨¨¯¯¨¨˜"ª¤....¤ ª"˜¨

Patrice Terrier

#33
Quotemaybe there is behind the DECLARE statement of Powerbasic the same

Perhaps...

As a matter of comparison, here are several declaration examples of the same WinLIFT API:

PowerBASIC
Quote  DECLARE FUNCTION skKnobGauge LIB "WinLIFT.dll" ALIAS "skKnobGauge" ( _
 BYVAL hOwner AS LONG, _            ' Handle of the window parent owner.
 zFullpathImageName AS ASCIIZ, _    ' Full path name to the gauge image.
 BYVAL x AS LONG, _                 ' X location of the gauge control.
 BYVAL y AS LONG, _                 ' Y location of the gauge control.
 BYVAL W AS LONG, _                 ' Width of the gauge control.
 BYVAL H AS LONG, _                 ' Height of the gauge control.
 BYVAL ButID AS LONG, _             ' Unique ID of the gauge control.
 BYVAL MinValue AS LONG, _          ' MAXIMUM range value (the exclusion zone is between the MINIMUM and MAXIMUM range).
 BYVAL MaxValue AS LONG, _          ' MAXIMUM range value (the exclusion zone is between the MINIMUM and MAXIMUM range).
 BYVAL UsePos AS LONG, _            ' 0 or initial angle value in degree to use.
 BYVAL Reserved AS LONG _           ' Must be NULL.
 ) AS LONG

WinDev
QuotePROCEDURE skKnobGauge( ...      
LOCAL hParent is int, ...       // Handle of the window parent owner.                                                
LOCAL sImagePath is string, ... // Full path name to the gauge image.                                                  
LOCAL x is int, ...             // X location of the gauge control.                                                  
LOCAL y is int, ...             // Y location of the gauge control.                                                  
LOCAL w is int, ...             // Width of the gauge control.                                                        
LOCAL h is int, ...             // Height of the gauge control.                                                      
LOCAL nID is int, ...           // Unique ID of the gauge control.                                                    
LOCAL MinValue is int, ...      // MAXIMUM range value (the exclusion zone is between the MINIMUM and MAXIMUM range).
LOCAL MaxValue is int, ...      // MAXIMUM range value (the exclusion zone is between the MINIMUM and MAXIMUM range).
LOCAL UsePos is int, ...        // 0 or initial angle value in degree to use.                                        
LOCAL reserved is int ...       // Must be NULL.                                                                      
)
nRet is int = API(WinLIFT, "skKnobGauge", hParent, (sImagePath), x, y, w, h, nID, MinValue, MaxValue, UsePos, reserved)
RESULT nRet

C++
QuoteHWND skKnobGauge (
   HWND hOwner,                     // Handle of the window parent owner.
   std::string sImageFile,          // Full path name to the gauge image.
   int x,                           // X location of the gauge control.
   int y,                           // Y location of the gauge control.
   int w,                           // Width of the gauge control.
   int h,                           // Height of the gauge control.
   int ButID,                       // Unique ID of the gauge control.
   int MinValue,                    // MAXIMUM range value (the exclusion zone is between the MINIMUM and MAXIMUM range).
   int MaxValue,                    // MAXIMUM range value (the exclusion zone is between the MINIMUM and MAXIMUM range).
   int UsePos,                      // 0 or initial angle value in degree to use.
   int Reserved                     // Must be NULL.
   ) {
   HWND hCtrl = 0;

   if (g_hWLFTdll) {
       typedef int (__stdcall *skProc) (HWND, char*, int, int, int, int, int, int, int, int, int);
       skProc hPROC = (skProc) GetProcAddress(g_hWLFTdll, "skKnobGauge");
       if (hPROC) {
           hCtrl = (HWND) hPROC(hOwner, (char*) sImageFile.c_str(), x, y, w, h, ButID, MinValue, MaxValue, UsePos, Reserved);
       }
   }
   return hCtrl;    
}

C#
Quote[DllImport(WINLIFT)]
public static extern IntPtr skKnobGauge (
IntPtr hOwner,           // Handle of the window parent owner.
string zFullpath,        // Full path name to the gauge image.
int x,                   // X location of the gauge control.
int y,                   // Y location of the gauge control.
int w,                   // Width of the gauge control.
int H,                   // Height of the gauge control.
int ButID,               // Unique ID of the gauge control.
int MinValue,            // MAXIMUM range value (the exclusion zone is between the MINIMUM and MAXIMUM range).
int MaxValue,            // MAXIMUM range value (the exclusion zone is between the MINIMUM and MAXIMUM range).
int UsePos,              // 0 or initial angle value in degree to use.
int Reserved AS LONG     // Must be NULL.
);


This type of API encapsulation allows me to port easily my code from one language to another.

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Jürgen Huhn

#34
Yes Patrice it must be so...

Do you have the Recources (Code) and you`re be able to write a little Function to read only the Proc Declarations for the Lib
from file as String and do the Implizit linking with your DLL from the strings in the file.  The include Routine of Visual C++ has sadly no
support for the Powerbasic .inc but nothing else is done wit other Languages by Visual C++.. ;)
.¸.•'´¯)¸.•'´¯)¸.•'´¯)¸.•'´¯)
¤ª"˜¨¨¯¯¨¨˜"ª¤....¤ ª"˜¨

Patrice Terrier

Translating my fiirst WinLIFT/GDImage project (HUDplus) to Visual Studio 2010.

That's a very good training to learn the C++ syntax.  8)

...

Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

James C. Fuller

Patrice,
 It may be possible to use Bcx3264 to help you in your conversions.
Here is Bcx3264 code and partial c++ code listing.
This is not a standard bcx conversion but is part of the Bcx3264 package.
the var types in the Import block must be c types.

James


#include "C:/bcx/include/Bcx3264.h"
CPP
NOMAIN

Import sqlite3 c_declare
sqlite3_open(a As const char*,b As long*) As int
sqlite3_close(a As long) As int
sqlite3_errmsg(b As long) As char*
sqlite3_exec(a As long,b As char*,c As void*,d As void*,e As char**) As int
sqlite3_free(a As void*) As void
sqlite3_libversion(a As void) As char*
End Import

Function main( argc As Integer,argv As char Ptr Ptr)
Dim As Long db
Raw As Integer rv
Dim v$
rv = sqlite3_open("jcf77.sdb",&db)


Print "rv = ",rv
v$ = sqlite3_libversion()
Print v$
sqlite3_close(db)

End Function


converted c++ code

// *************************************************
//          User Defined Types And Unions
// *************************************************
typedef int  (__cdecl *BCXFPROT1)(const char*,long*);
typedef int  (__cdecl *BCXFPROT2)(long);
typedef char*  (__cdecl *BCXFPROT3)(long);
typedef int  (__cdecl *BCXFPROT4)(long,char*,void*,void*,char**);
typedef void (__cdecl *BCXFPROT5)(void*);
typedef char*  (__cdecl *BCXFPROT6)(void);

// *************************************************
//                System Variables
// *************************************************

static BCXFPROT1 sqlite3_open;
static BCXFPROT2 sqlite3_close;
static BCXFPROT3 sqlite3_errmsg;
static BCXFPROT4 sqlite3_exec;
static BCXFPROT5 sqlite3_free;
static BCXFPROT6 sqlite3_libversion;

.........................

int main (int argc, char** argv)
{

HMODULE  H_SQLITE3 = LoadLibrary("sqlite3.dll");
sqlite3_open=(BCXFPROT1)GetProcAddress(H_SQLITE3, "sqlite3_open");
sqlite3_close=(BCXFPROT2)GetProcAddress(H_SQLITE3, "sqlite3_close");
sqlite3_errmsg=(BCXFPROT3)GetProcAddress(H_SQLITE3, "sqlite3_errmsg");
sqlite3_exec=(BCXFPROT4)GetProcAddress(H_SQLITE3, "sqlite3_exec");
sqlite3_free=(BCXFPROT5)GetProcAddress(H_SQLITE3, "sqlite3_free");
sqlite3_libversion=(BCXFPROT6)GetProcAddress(H_SQLITE3, "sqlite3_libversion");

// ****************************************



Patrice Terrier

James,

Thank you.

Indeed i am almost done with my conversion.
Knowing C#, and having translated much C and C++ code to PB (like Direct2D), helped me much.

I am porting WinLIFT and GDImage to c++, because i am looking for new market opportunities.  ;)

I shall post the HUDplus c++ source code project here, once done, to share what i have learned.

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Patrice Terrier

#38
I have completed the translation of my PB's HUDplus project to C++,
and the size of the resulting executable are:

PowerBASIC: 30720 bytes.

C++ with /Ox (full optimization): 30720 bytes.
C++ with /O1 (size reduction): 25088 bytes.
C++ with /O2 (speed boost): 30720 bytes.

Thus, i would say, PB does already a pretty good job.  8)

Added:
forget to say that Viual Studio IntelliSense is a wonderful tool for a beginner like me.  ;)

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Peter Weis

Hi Patrice,
I do not think that you are a beginner! 're Fully fit on it. I would not get out so quickly. I have 15 years no C + + programming!
The 5 Kb size reduction with less power compared to Basic. Expected from the string of motor PowerBasic come.

Regards Peter

Patrice Terrier

#40
Peter--

I am learning C++, because i think there will be more people interrested by WinLIFT and GDImage in the Microsoft's galaxy than in the PB's world.

Indeed, i should have learned C++ much sooner.  :-[

...
 
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Peter Weis

#41
Hi Patrice, :)
With c or c + + is open to you in any case the 64 bit world. That is in Power Basic unfortunately not the case. I like c actually not so. Better to assembler because I have the full control. Could I still think that you Winlift gdiimage and completely to C + + portierst, then you had a Complete encapsulation. You could then Winlift Gdiimage or use of different windows with different properties. Without which they influence each other.
z.B Winlift a class and a class gdiimage. Each class has it's own instancen. You can call several times each class! :D
 
 
Regards Peter

Patrice Terrier

#42
Peter--

Actually, my plan was to enable the use of WinLIFT and GDImage altogether with C++ 32-bit, thus the first thing was to provide the correct API headers.

But in the long run, when i become more familiar with C++, i shall probably create the 64-bit version with Visual Studio (because 64-bit is my main motivation to learn C++).

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Peter Weis

Hi Patrice, ;)

I see this, too! You can of course at the moment only with C + +, C, Assembler, Delphi or Visual Net (Basic) or PureBasic to achieve a 64 connection. Hope I did not forget any language! It would of course not bad in a complete encapsulation of gdimage and think Windlift. This is only possible when you put it in the above mentioned programming languages object oriented programm for new. This would go well with Power Basic 9.0, but unfortunately only 32 bits :'(.

But whom do you need a 64 bit connection, you will sooner or later anyway and gdimage winlift need to write new Who there in the foreseeable future, no 64-bit Power Basic.

I would like to open up any new 64-bit debate. It took me quite annoyed last month the discussions that have run here and in other forums.

Regards Peter

Jürgen Huhn

Hallöchen Peter,

i think PowerBasic has the Choice beetween to take the Train into the Future or to sink and to fade away sooner or later.
I`m also on the way to use more and more 64bit-Compiler and 64bit Datatypes to work with the gain of 64bit advantage.
To produce a Software wich must support the full access to newer Hardware no other option remains.

I hope "PB Win 64bit" soon comes!

Gruß, Jürgen..
.¸.•'´¯)¸.•'´¯)¸.•'´¯)¸.•'´¯)
¤ª"˜¨¨¯¯¨¨˜"ª¤....¤ ª"˜¨