Using windows objects?
Posted: Mon Oct 06, 2003 2:59 pm
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.
http://www.purebasic.com
https://www.purebasic.fr/english/
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
EndDataSectionCode: 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
Code: Select all
#IID_DirectDraw7 = "$10,$11,$0110,$FF10,$FF10"
And then:
Address = GetCLSID(#IID_DirectDraw7)
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
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\).aXend wrote:The advanced example DirectX7.pb doesn't use the Interface option at all!!
Code: Select all
...
If CallFunction(0,"DirectDrawCreateEx",0,@DirectDraw.IDirectDraw7,?IID_IDirectDraw7,0) <> #DD_OK
...
If DirectDraw\CreateSurface(SurfaceDescriptor, @PrimarySurface.IDirectDrawSurface7, 0) <> #DD_OK
...How can I look into this resident file?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\).
See: can someone shed some light on interfacedx.res ?aXend wrote:How can I look into this resident file?