Page 1 of 2

Using windows objects?

Posted: Mon Oct 06, 2003 2:59 pm
by Justin
The new com stuff looks great but, it can be used to acces the windows objects(shell,browser,etc..) easily?, without an example it's a bit difficult to figure out how it works in PB.

Posted: Mon Oct 06, 2003 4:45 pm
by Psychophanta

Posted: Mon Oct 06, 2003 6:11 pm
by Justin
i could not find any reference to a windows native object, all is about creating your own

Posted: Mon Oct 06, 2003 8:15 pm
by Psychophanta
You can see PB C.O.M. (ActiveX) code at:
http://robsite.de/php/pureboard/viewtop ... hlight=com

and if you don't understand german, then can use this to translate:

http://translation.paralink.com/urlmode.asp

I requested for André Beer to collect OOP small examples made with this PB 3.80 release, for his work; PB code-archive (www.purearea.net), and he is waiting for new C.O.M. (ActiveX) and DX OOP stuff here in this forum and in the german one to include it in the PureBasic code-archive.

Thanx !)

Posted: Mon Oct 06, 2003 9:20 pm
by Fred
There is an example of Raw DirectX 7 example in "Examples/Advanced - Examples/DirectX 7" drawer. Nothign can't stop you now :)

Posted: Mon Oct 06, 2003 10:25 pm
by Justin
Thanks, that gave me the clue. here's a simple example of the taskbar object based on a code by Danilo i think. it removes the window caption from the taskbar.

Code: Select all

CoInitialize_(0)

hwnd=OpenWindow(0,10,10,500,500,#PB_Window_SystemMenu,"Hello World")

if CoCreateInstance_(?CLSID_TaskbarList,0,1,?IID_ITaskbarList,@pobj.ITaskbarList)=0
	pobj\HrInit()
	pobj\DeleteTab(hwnd)
	
	Repeat   
  Until WaitWindowEvent()=#PB_EventCloseWindow
  
  pobj\Release()
endif

end

DataSection
CLSID_TaskbarList:
Data.l $56FDF344
Data.w $FD6D,$11D0
Data.b $95,$8A,$00,$60,$97,$C9,$A0,$90

IID_ITaskbarList:
Data.l $56fdf342
Data.w $FD6D,$11D0
Data.b $95,$8A,$00,$60,$97,$C9,$A0,$90
EndDataSection
now it's much easier. this increases the scope of PB. we still have to work at the CLSID and IID, maybe it could be included in some resident?

Posted: Tue Oct 07, 2003 8:58 am
by Fred
About the CSLID and such we're trying to find an elegant solution, as the data can't be put in a residents. Never the less, we could provide a file with all the data declared and some compiler directive to enable/disable the needed one.

Posted: Tue Oct 07, 2003 9:28 am
by dmoc
It's been over six months (and one hd crash) so I need to check this out later but I have old code that returns ID's given the name of the object, ie, to help emulate statements in other languages like "an_object = CreateObject("Excel")". Maybe the same could/should now be built-in to PB to complement the new COM features ala "id = GetCLSID("obj_name")"? I think this actually is what my code did.

Hopefully I have misread the post but wouldn't it be an awful waste if CLSID's, which are already stored in the registry, are reproduced again in a res file?

Another question, my memory fails me, but if you are creating a brand new COM object how do you go about getting an ID for it? My understanding is that they are unique to the class across machines or am I wrong?

I'm deeply in 3D at the mo but already envisaging a COM interface to my engine.

Edit: Yo! Here yer go!...

Code: Select all

Structure CLSIDa
  Data1.l;
  Data2.w;
  Data3.w;
  Data4.b[8];
EndStructure

Structure CLSIDb
  d.b[36]
EndStructure

clsExcelApp.CLSIDa
;clsExcelApp.CLSIDb

ProgID.s      = "Excel.Application"
IDBufferLen.w = 2*Len(ProgID)+2
IDBuffer      = AllocateMemory(9, IDBufferLen)

;int MultiByteToWideChar(
;    UINT CodePage,  // code page 
;    DWORD dwFlags,  // character-type options 
;    LPCSTR lpMultiByteStr,  // address of string to map 
;    int cchMultiByte, // number of characters in string 
;    LPWSTR lpWideCharStr, // address of wide-character buffer 
;    int cchWideChar   // size of buffer 
;   );
IDLen.w = MultiByteToWideChar_(#CP_ACP, 0, ProgID, -1, IDBuffer, IDBufferLen)

If IDLen=0
  Debug "MultiByteToWideChar Failed"
  End
EndIf

;HRESULT CLSIDFromProgID( LPCOLESTR lpszProgID, //Pointer to the ProgID 
; 			        LPCLSID   pclsid  	//Pointer to the CLSID 
;); 
;result.l = CLSIDFromProgID_(IDBuffer, @pclsExcelApp.l);
result.l = CLSIDFromProgID_(IDBuffer, @clsExcelApp);

Select result
  Case #S_OK 
    Debug "The CLSID was retrieved successfully."

    ;WINOLEAPI StringFromCLSID( REFCLSID rclsid, ; //CLSID To be converted 
    ;                           LPOLESTR * ppsz  ; //Indirect pointer to the resulting string on Return 
    ;); 
    
    result = StringFromCLSID_( clsExcelApp, @pCS.l)
    If result = #S_OK
      cs.s = Space(32*2-1)

      ;int WideCharToMultiByte(
      ;    UINT CodePage,	      // code page 
      ;    DWORD dwFlags,	      // performance and mapping flags 
      ;    LPCWSTR lpWideCharStr,	// address of wide-character string 
      ;    int cchWideChar,	      // number of characters in string 
      ;    LPSTR lpMultiByteStr,	// address of buffer for new string 
      ;    int cchMultiByte,	      // size of buffer 
      ;    LPCSTR lpDefaultChar,	// address of default for unmappable characters  
      ;    LPBOOL lpUsedDefaultChar // address of flag set when default char. used 
      ;   );


      CSLen.w = WideCharToMultiByte_(#CP_ACP, 0, pCS, -1, @cs, Len(cs), 0, 0)

      If CSLen
        Debug "%"+cs+"%"
        SetClipboardText(cs)
      Else
        Debug "WideCharToMultiByte Failed!"
      EndIf
      
    EndIf

  Case #CO_E_CLASSSTRING 
    Debug "The registered CLSID For the ProgID is invalid."

  Case #REGDB_E_WRITEREGDB 
    Debug "An error occurred writing the CLSID to the registry"
EndSelect

Posted: Tue Oct 07, 2003 9:59 am
by Justin
Yes, shouldn't be too difficult to have a PB procedure for createobject(), i'll try it.

About creating a clsid, i think is done with CoCreateGuid(), take a look at msdn. What i don't know is how to register a PB object(dll ?) to use it with another language, anyone?

Posted: Tue Oct 07, 2003 10:17 am
by Fred
By reading you posts, I come up with this: we could store the CSLID and such complex variables in a string and then have a function to get a pointer to this. The big advantage is it can be put in the resident easily.

Code: Select all


  #IID_DirectDraw7 = "$10,$11,$0110,$FF10,$FF10"
  
  And then:

  Address = GetCLSID(#IID_DirectDraw7)


Posted: Tue Oct 07, 2003 10:32 am
by dmoc
OK, maybe I am missing the plot so here's another example...

Code: Select all

Structure CLSIDa
  Data1.l;
  Data2.w;
  Data3.w;
  Data4.b[8];
EndStructure

Structure CLSIDb
  d.b[36]
EndStructure

clsid.CLSIDa
;clsid.CLSIDb

;ProgID.s      = "Excel.Application"
ProgID.s      = "DIRECT.DirectX8.0"
IDBufferLen.w = 2*Len(ProgID)+2
IDBuffer      = AllocateMemory(9, IDBufferLen)

IDLen.w = MultiByteToWideChar_(#CP_ACP, 0, ProgID, -1, IDBuffer, IDBufferLen)

If IDLen=0
  Debug "MultiByteToWideChar Failed"
  End
EndIf

result.l = CLSIDFromProgID_(IDBuffer, @clsid);

Select result
  Case #S_OK 
    Debug "The CLSID was retrieved successfully."

    result = StringFromCLSID_( clsid, @pCS.l)
    If result = #S_OK
      cs.s = Space(32*2-1)
      CSLen.w = WideCharToMultiByte_(#CP_ACP, 0, pCS, -1, @cs, Len(cs), 0, 0)

      If CSLen
        Debug "%"+cs+"%"
        SetClipboardText(cs)
      Else
        Debug "WideCharToMultiByte Failed!"
      EndIf
      
    EndIf

  Case #CO_E_CLASSSTRING 
    Debug "The registered CLSID For the ProgID is invalid."

  Case #REGDB_E_WRITEREGDB 
    Debug "An error occurred writing the CLSID to the registry"
EndSelect

Posted: Tue Oct 07, 2003 1:54 pm
by aXend
The suggestion to get a CreateObject() with PureBasic looks nice to me, since I don't understand all the other stuff very well. The Interface options isn't very clear. The advanced example DirectX7.pb doesn't use the Interface option at all!!

I'm not that familiar with CLSID and programming COM, I like to keep it (Pure)Basic, like using ActiveXObject (with Javascript). I turned to PureBasic to get compiled applications. I have some ActiveX dll's that I could use with Javascript, but how do I use them with PureBasic?

The code provided by dmoc works fine with me, but what do I do with that CLSID? May be that's a curse, but I can't help it. Who can give me a clue how to use my ActiveX dll's ?

Posted: Tue Oct 07, 2003 2:00 pm
by helpy
aXend wrote:The advanced example DirectX7.pb doesn't use the Interface option at all!!
That is not right! But you cannot see the Interface-Declaration in this example because it is implemented in PureBasic (Resident File InterfaceDX.res in folder ...\PureBasic\Residents\).

In the code of the DirectX 7.pb you find:

Code: Select all

...

  If CallFunction(0,"DirectDrawCreateEx",0,@DirectDraw.IDirectDraw7,?IID_IDirectDraw7,0) <> #DD_OK

...

If DirectDraw\CreateSurface(SurfaceDescriptor, @PrimarySurface.IDirectDrawSurface7, 0) <> #DD_OK

...
This example uses the Interfaces IDirectDraw7 and IDirectDrawSurface7.

cu, helpy

Posted: Tue Oct 07, 2003 2:27 pm
by aXend
helpy wrote:That is not right! But you cannot see the Interface-Declaration in this example because it is implemented in PureBasic (Resident File InterfaceDX.res in folder ...\PureBasic\Residents\).
How can I look into this resident file?

Posted: Tue Oct 07, 2003 2:53 pm
by helpy
aXend wrote:How can I look into this resident file?
See: can someone shed some light on interfacedx.res ?

cu, helpy