Using windows objects?

Just starting out? Need help? Post your questions and find answers here.
Justin
Addict
Addict
Posts: 956
Joined: Sat Apr 26, 2003 2:49 pm

Using windows objects?

Post 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.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Justin
Addict
Addict
Posts: 956
Joined: Sat Apr 26, 2003 2:49 pm

Post by Justin »

i could not find any reference to a windows native object, all is about creating your own
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post 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 !)
Fred
Administrator
Administrator
Posts: 18351
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

There is an example of Raw DirectX 7 example in "Examples/Advanced - Examples/DirectX 7" drawer. Nothign can't stop you now :)
Justin
Addict
Addict
Posts: 956
Joined: Sat Apr 26, 2003 2:49 pm

Post 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?
Fred
Administrator
Administrator
Posts: 18351
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post 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.
dmoc
Enthusiast
Enthusiast
Posts: 739
Joined: Sat Apr 26, 2003 12:40 am

Post 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
Justin
Addict
Addict
Posts: 956
Joined: Sat Apr 26, 2003 2:49 pm

Post 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?
Fred
Administrator
Administrator
Posts: 18351
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post 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)

dmoc
Enthusiast
Enthusiast
Posts: 739
Joined: Sat Apr 26, 2003 12:40 am

Post 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
aXend
Enthusiast
Enthusiast
Posts: 103
Joined: Tue Oct 07, 2003 1:21 pm
Location: Netherlands

Post 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 ?
User avatar
helpy
Enthusiast
Enthusiast
Posts: 552
Joined: Sat Jun 28, 2003 12:01 am

Post 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
aXend
Enthusiast
Enthusiast
Posts: 103
Joined: Tue Oct 07, 2003 1:21 pm
Location: Netherlands

Post 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?
User avatar
helpy
Enthusiast
Enthusiast
Posts: 552
Joined: Sat Jun 28, 2003 12:01 am

Post by helpy »

aXend wrote:How can I look into this resident file?
See: can someone shed some light on interfacedx.res ?

cu, helpy
Post Reply