March 28, 2024, 09:10:32 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


COM example

Started by Ionic Wind Support Team, December 14, 2005, 06:28:20 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ionic Wind Support Team

I mentioned in another topic that COM and classes were one in the same.  A COM interface consists of a pointer to a class, which contains all virtual functions.  Even though COM support hasn't been officially added yet to Aurora you can still use it by creating a class of virtual functions and having a pointer to that class filled in by CoCreateInstance.

This little example uses the shell COM object to minimize all of your windows.


#use "ole32.lib"
#use "uuid.lib"

struct GUID,1
{
int data1;
word data2;
word data3;
byte data4[8];
}

EXTERN _CLSID_Shell as GUID;
EXTERN _IID_IShellDispatch as GUID;

class IUnknown
{
/*** IUnknown methods ***/
declare virtual QueryInterface(riid as POINTER, ppvObj as POINTER),int;
declare virtual AddRef(),int;
declare virtual Release(),int;
}

class IDispatch : IUnknown
{
/*** IDispatch methods **/
declare virtual GetTypeInfoCount(pctinfo as UINT BYREF),int;
declare virtual GetTypeInfo(iTInfo as UINT,lcid as POINTER,ppTInfo as POINTER),int;
declare virtual GetIDsOfNames(riid as GUID,rgszNames as STRING,cNames as UINT,lcid as POINTER,rgDispID as GUID),int;
declare virtual Invoke(dispIdMember as INT,riid as GUID,lcid as POINTER,wFlags as WORD,pDispParams as POINTER,pVarResult as POINTER,pExcepInfo as POINTER,puArgErr as UINT BYREF),int;
}

class IShellDispatch : IDispatch
{
/*** IShellDispatch methods ***/
declare virtual get_Application(IDispatch as POINTER),int;
declare virtual get_Parent(IDispatch as POINTER),int;
declare virtual NameSpace(vDir as POINTER, folder as POINTER),int;
declare virtual BrowseForFolder(hwnd as UINT, title as STRING, options as INT, RootFolder as POINTER, Folder as POINTER),int;
declare virtual Windows(IDispatch as POINTER),int;
declare virtual Open(vDir as POINTER),int;
declare virtual Explore(vDir as POINTER),int;
declare virtual MinimizeAll(),int;
declare virtual UndoMinimizeALL(),int;
declare virtual FileRun(),int;
declare virtual CascadeWindows(),int;
declare virtual TileVertically(),int;
declare virtual TileHorizontally(),int;
declare virtual ShutdownWindows(),int;
declare virtual Suspend(),int;
declare virtual EjectPC(),int;
declare virtual SetTime(),int;
declare virtual TrayProperties(),int;
declare virtual Help(),int;
declare virtual FindFiles(),int;
declare virtual FindComputer(),int;
declare virtual RefreshMenu(),int;
declare virtual ControlPanelItem(szDir as STRING),int;
}

DECLARE IMPORT,CoInitialize(pointer lpvoid),INT;
DECLARE IMPORT,CoUninitialize();
DECLARE IMPORT,CoCreateInstance(GUID rclsid,pointer pUnknOuter,unsigned int dwClsContext,GUID riid,pointer ppv),int;

CONST CLSCTX_INPROC_SERVER = 1;
CONST CLSCTX_SERVER = 1 | 4 | 16;

global sub main()
{
CoInitialize(NULL);

pointer psl;

hres = CoCreateInstance(_CLSID_Shell, NULL, CLSCTX_SERVER, _IID_IShellDispatch, &psl);
if (hres = 0)
{
*(IShellDispatch)psl.MinimizeAll();
*(IShellDispatch)psl.Release();
}

CoUninitialize();
return 0;
}
Ionic Wind Support Team

Zen

Before i start reading into COM, because i want to learn a bit of it. Does Aurora use COM or COM+ or both?

Lewis

DominiqueB

Hello,
just a question about the above prog:
Is there a way not to show the console when executing the .exe if compiled in console mode ?
When compiled in windows mode the console doesn't shows, but if compiled in console mode the console appears and desappears. Some prog doesn't need any interraction with the user, so how can i do it ?

Thank's for the info.

Dominique

Parker

Just compile in windows mode and don't use OpenConsole(). But make sure you have a way for the program to end, since windows mode usually relies on the close button to allow the program to end.

nico

I have an errors: ???

Compiling...
Aurora15.src
No Errors

Linking...
Aurora Linker v1.0 Copyright ÂÃ,©2005,2006 Ionic Wind Software
Unresolved external IUnknown@QueryInterface
Error: Unresolved extern IUnknown@QueryInterface
Error: Unresolved extern IUnknown@AddRef
Error: Unresolved extern IUnknown@Release
Error: Unresolved extern IDispatch@GetTypeInfoCount
Error: Unresolved extern IDispatch@GetTypeInfo
Error: Unresolved extern IDispatch@GetIDsOfNames
Error: Unresolved extern IDispatch@Invoke
Error: Unresolved extern IShellDispatch@get_Application
Error: Unresolved extern IShellDispatch@get_Parent
Error: Unresolved extern IShellDispatch@NameSpace
Error: Unresolved extern IShellDispatch@BrowseForFolder
Error: Unresolved extern IShellDispatch@Windows
Error: Unresolved extern IShellDispatch@Open
Error: Unresolved extern IShellDispatch@Explore
Error: Unresolved extern IShellDispatch@MinimizeAll
Error: Unresolved extern IShellDispatch@UndoMinimizeALL
Error: Unresolved extern IShellDispatch@FileRun
Error: Unresolved extern IShellDispatch@CascadeWindows
Error: Unresolved extern IShellDispatch@TileVertically
Error: Unresolved extern IShellDispatch@TileHorizontally
Error: Unresolved extern IShellDispatch@ShutdownWindows
Error: Unresolved extern IShellDispatch@Suspend
Error: Unresolved extern IShellDispatch@EjectPC
Error: Unresolved extern IShellDispatch@SetTime
Error: Unresolved extern IShellDispatch@TrayProperties
Error: Unresolved extern IShellDispatch@Help
Error: Unresolved extern IShellDispatch@FindFiles
Error: Unresolved extern IShellDispatch@FindComputer
Error: Unresolved extern IShellDispatch@RefreshMenu
Error: Unresolved extern IShellDispatch@ControlPanelItem
Error(s) in linking C:\Program Files\Aurora\Aurora15.exe


Ionic Wind Support Team

Because you're looking at a two year old topic.  COM support was added to Aurora long ago and this snippet was only for testing the language back in the early Alpha stages.  Look in your examples folder that comes with Aurora.  The file name is "shell_com_example.src"

Paul.
Ionic Wind Support Team