Deprecated: Array and string offset access syntax with curly braces is deprecated in /homepages/21/d38531796/htdocs/jose/smfforum/Sources/Subs.php on line 3825
c++ client PowerBASIC Server

Author Topic: c++ client PowerBASIC Server  (Read 27788 times)

0 Members and 1 Guest are viewing this topic.

Offline Dominic Mitchell

  • Jr. Member
  • **
  • Posts: 64
  • User-Rate: +11/-5
    • Prometheus Software
Re: c++ client PowerBASIC Server
« Reply #30 on: January 30, 2009, 11:24:59 PM »
http://www.phnxthunder.com/forums/phpBB2/viewtopic.php?t=714

The tree control in the screenshots in the above link is visual ActiveX control I wrote using PowerBASIC.
It was written using low-level COM not PB COM.

Something you will need to be aware of when writing a server or even an OLE container that hands out
objects to clients, is what is known as the lock count on an object.  When the reference count on an
object you handed out reaches zero, it does not necessarily mean that you can go ahead and destroy it.

Dominic Mitchell
Phoenix Visual Designer
http://www.phnxthunder.com

Offline Dominic Mitchell

  • Jr. Member
  • **
  • Posts: 64
  • User-Rate: +11/-5
    • Prometheus Software
Re: c++ client PowerBASIC Server
« Reply #31 on: January 30, 2009, 11:38:53 PM »
What James is doing is creating a server that creates windows.  Those windows are not ActiveX controls
by any stretch of the imagination.
Dominic Mitchell
Phoenix Visual Designer
http://www.phnxthunder.com

Offline Frederick J. Harris

  • Hero Member
  • *****
  • Posts: 914
  • User-Rate: +16/-0
    • Frederick J. Harris
Re: c++ client PowerBASIC Server
« Reply #32 on: January 31, 2009, 12:35:08 AM »
Are you speaking of something above & beyond this type of construct Dominic?

Code: [Select]
STDAPI DllCanUnloadNow()
{                                   
 if(g_lObjs||g_lLocks)         
    return S_FALSE;           
 else                               
    return S_OK;                 
}                                   

in other words...

If CountOfObjects>0  Or CountOfServerLocks > 0 Then
   Don't Unload
Else
   No Reason To Stay!  Bye Bye (CoFreeUnusedLibraries() Come And Get Me!)
End If

Offline Dominic Mitchell

  • Jr. Member
  • **
  • Posts: 64
  • User-Rate: +11/-5
    • Prometheus Software
Re: c++ client PowerBASIC Server
« Reply #33 on: January 31, 2009, 02:07:36 AM »
That code snippet you showed is related to the IClassFactory::LockServer method and is the same code I use
in the tree control. But I was also thinking about servers(both in and out of process) and OLE containers that
support Linking to objects. This is where the IExternalConnection interface comes in.  See, for example,

http://www.microsoft.com/msj/0197/activex/activex0197.aspx
Dominic Mitchell
Phoenix Visual Designer
http://www.phnxthunder.com

Offline James C. Fuller

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 597
  • User-Rate: +11/-8
Re: c++ client PowerBASIC Server
« Reply #34 on: January 31, 2009, 02:37:31 PM »


  Is it possible to use the "c" method access I demonstrated with Visual Basic: Loading an registered interface
directly from a dll.

As I stated I only have the latest vs 2008 installed so I can't test. I do have a copy of vb5cce somewhere?

James

Offline Frederick J. Harris

  • Hero Member
  • *****
  • Posts: 914
  • User-Rate: +16/-0
    • Frederick J. Harris
Re: c++ client PowerBASIC Server
« Reply #35 on: January 31, 2009, 07:18:06 PM »
I've never tried it James, but everything I know about computers (which is considerably less than you, I'm sure), tells me it can be done.  After all, structures in memory are structures in memory, and Api function calls are Api function calls, so as long as the right parameters & structures are used - I'd expect it to work.  However, I know little of the underpinnings of the .NET framework, so I don't know just what functions/interfaces would be helpful there.  With the Visual Studio 4, 5 & 6 stuff though I imagine it would work. 

As I continue my study of this rather complicated (h***, its more than complicated.  I think one could just about call it 'rocket science'.) material, I hope to end up with my own version of a TypeLib browser where I could use perhaps a radio button or check box to indicate whether I want C++ declares or PowerBASIC declares and interfaces generated.  I had been working on that several months ago, and actually had the code roughed out enough that it was outputting pretty good declares for me.  There were a few minor problems though and I got to tearing it up pretty good.  At some point I'd like to get back to that work though.  I pretty much consider myself a PowerBASIC programmer rather than a C++ programmer, but what keeps me prettily heavily in the C++ language is that in my work I create handheld data recorder programs for our field data collection in the PA Bur of Forestry, and for that I use Microsoft's eMbedded Visual C++ 4.0.  I've never found a suitable alternative to that.  There are alternatives, but by suitable I mean ability to get real low level into the OS to modify things as I need to.

However, my C++ knowledge has improved quite a bit over the past year or two due to the fact that on the last major programming project I did I decided to use C++ instead of the C I'm more familiar with, and what with all this studying of COM I'm doing, I'm getting a better sense of C++.  For desktop Windows programming, which I also do a lot of, I invariably use PowerBASIC, as its a much more productive environment.

If you want any of that typelib code I've got I'd be happy to give it to you.  Its C++ though.

Added five minutes later:

One other thing James.  If you want to try accessing VB ActiveX controls from C why don't you install that VB5 you have.  You had mentioned you had that in other posts.  I expect you would get a good number of common ActiveX controls installed to give you something to work with.  The one control I really missed when I moved to PB from VB was the MSFlexGrid control.  Its an Ocx or ActiveX control.   To a lesser extent I missed the MSCal control, which is another ActiveX control.  I was able to first get these controls working through code Jose Posted & his TypeLib browsers.  In the generated PowerBASIC code from his TypeLib browser it can be clearly seen how he created the objects in memory (the interfaces) and was able to receive events from these controls.  Essentially, he had to do exactly what a C programmer would do to accomplish this.  In C or pre v9 PowerBASIC, you need to either allocate memory for the VTables or use Types containing pointers to the various interface functions, just as you were doing in your last code you posted.  That's kind of why I'm recommending what I am in terms of studying some of Jose's excellent code.  I believe you would need one of his earlier TypeLib browsers however; with PB9 it wasn't necessary to do any of that to receive events.  Also, I'm not sure how up on Events you are.  You've got to study up on that and it is quite complex - especially so when you get into the enumerators.
« Last Edit: January 31, 2009, 07:37:52 PM by Frederick J. Harris »

Offline Frederick J. Harris

  • Hero Member
  • *****
  • Posts: 914
  • User-Rate: +16/-0
    • Frederick J. Harris
Re: c++ client PowerBASIC Server
« Reply #36 on: January 31, 2009, 07:48:02 PM »
Question perhaps for Dominic.   That control looks really nice Dominic.   I'm sure it took a lot of hard work.  You had touched on a point that I've wondered about quite a bit, and that is if it is even possible to tie into PowerBASIC's current COM infrastructure to build a full ActiveX control, or whether it is indeed unfortunately necessary to start from scratch and do everything low level as you apparently have done.  I'm still in the stage of just learning this material yet, and am not yet ready to study the ActiveX end of it, but the issue has occurred to me numerous times. 

Offline James C. Fuller

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 597
  • User-Rate: +11/-8
Re: c++ client PowerBASIC Server
« Reply #37 on: January 31, 2009, 07:49:37 PM »
Re:TypeLib code
A couple days ago I thought I might go that route but instead I wrote a little Pb parser for the Pb inc code
created by José's browser. I still need to tweak the c++ code for Pb longs/dwords to HWND,HFONT,HANDLE and a
few others. I had to go through and add ALIAS to all my methods and Properties (actually I wrote a program to do it) first.
I'm plugging away at translating the PB Client code  to c++. I'm using BCC at the moment but the code should
be fine with g++.


I'm not really interested in accessing ActiveX or anything else from PB at this time. Right now I'm focused on
access of PB COM servers from other languages.
I have extreme tunnel vision when it comes to doing most anything,especially programming.
I don't multi-task well at all. One thing at a time.
James


Offline Frederick J. Harris

  • Hero Member
  • *****
  • Posts: 914
  • User-Rate: +16/-0
    • Frederick J. Harris
Re: c++ client PowerBASIC Server
« Reply #38 on: January 31, 2009, 08:50:50 PM »
Quote
I have extreme tunnel vision when it comes to doing most anything,especially programming.

That's exactly how I am too.

Weren't you calling DllGetClassObject() in some of your earlier code on that PB Dll COM server you made?  If my memory serves and without checking I thought you were.  Thatt DllGetClassObject() function is, I believe, part of the COM standard, and so any PB Dll COM server should have it.  And that's the beauty of COM.  Once you're 'in', so to speak, you should be able to use QueryInterface() to get whatever you have prior knowledge of through headers or Type Libraries.

Offline James C. Fuller

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 597
  • User-Rate: +11/-8
Re: c++ client PowerBASIC Server
« Reply #39 on: February 01, 2009, 03:11:56 PM »
Fred,
  Quick c/c++ question:
How would you convert this PB  snippet? The %TCN_LAST TO %TCN_FIRST. I first check that it's Tab Control Message before I break it down further for explicit messages. I'm a bit familiar with switch case but could find no info on from To type. Would if's be more appropriate?
Thanks
James


Code: [Select]
        CASE %WM_NOTIFY
            lpNmHdr = CB.LPARAM
            SELECT CASE @lpNmHdr.code
                CASE %TCN_LAST TO %TCN_FIRST



Offline James C. Fuller

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 597
  • User-Rate: +11/-8
Re: c++ client PowerBASIC Server
« Reply #40 on: February 01, 2009, 06:53:56 PM »
Never mind I got it I think?

if((lpNmHdr->code >= TCN_LAST) & (lpNmHdr->code <= TCN_FIRST))

James

Offline Frederick J. Harris

  • Hero Member
  • *****
  • Posts: 914
  • User-Rate: +16/-0
    • Frederick J. Harris
Re: c++ client PowerBASIC Server
« Reply #41 on: February 01, 2009, 07:23:14 PM »
Hi James!

     Yes, that works.  In cases where there are more than two or three the if construct becomes awkward, and you'll see this form of construct used...

Code: [Select]
switch(charCode)
{
  case 48:
  case 49:
  case 50:
  case 51:
  case 52:
  case 53:
  case 54
  case 55
  case 56
  case 57:
     //run some code;
     break;
  case other logic
    break
}


...which takes advantage of the fact that C/C++ doesn't break out of a switch until it encounters a 'break'.  The above snippet might be if you are testing for keypresses that are numeric digits.  This is but yet another example of the crudity of C/C++ syntax.  In my mind the BASIC Select Case is so much nicer.

Offline James C Morgan

  • Newbie
  • *
  • Posts: 3
  • User-Rate: +0/-0
Re: c++ client PowerBASIC Server
« Reply #42 on: February 18, 2022, 03:21:12 AM »
i most basic console one uses

locate 15,4: Print "hi"

is there a c++ or win32api that can perform this
or can one write a routine does the same