Page 1 of 1

Interface / EndInterface

Posted: Thu Oct 16, 2003 10:56 am
by mp303
The amount of information about these new keywords in the
help file is extremely sparse and confusing.

First off, what are they for? The help section opens up
with the following:

"Interfaces are used to access Object Oriented modules,
like COM (Component Object Model) or DirectX dynamic
libraries (DLL)."

To begin with - to my knowledge - there is no such thing
as a "DirectX dynamic library" on Windows ... they must
mean "ActiveX", not "DirectX"??

Also, I'm confused - will the new Interface keyword
actually allow you to do all this? Will I be able to
import (or manually port) the OO interface for a COM
object, like say, the Macromedia Flash player, or the
Microsoft Scripting object? ... sounds from the
description like it would, but I don't see how? there
doesn't seem to be any support (nothing documented)
for the visual embedding of such controls in the GUI,
like an "ActiveX Gadget" or something like that?

...

The help goes on with the following:

"Most of the standard Windows interfaces are already
implemented in a resident file which allow a direct
use of these objects"

What objects would those be? Where is this residents
file? Is there any documentation for these objects,
or at least a list of the ported object interfaces so
you can find the documentation for them elsewhere?

...

The help then provides a couple of examples - but
these don't have any implementation code for any of
the declared methods ... how do you implement methods
for declared interfaces?

or are you not supposed to write code for methods?
if not, where does the code come from then? - if it
comes from an external DLL (like an ActiveX control),
how does PB find these objects? where do you provide
the GUID or the .DLL filename of the object??

...

And finally the help ends abruptly with:

"Example 3 : Creating its own object in PureBasic
(see advanced examples)"

I've looked everywhere, and there don't seem to be
any examples? I searched in all files in the PB dir
for "Interface", and nothing turns up ... looks like
the help author just stopped writing here???

...

In short: what are the commands for, and how do you
use them? This information, and at least one working
example, should have been in the help files. Or not?

Posted: Thu Oct 16, 2003 12:41 pm
by Kale
Yes, i know these new commands will be very powerful to use and open up new avenues to programmers but i am still a bit confused to on how to use these new commands. I would like to see more examples and a more lengthy description on how to use them.
Most of the standard Windows interfaces are already implemented in a resident file which allow a direct use of these objects.
I understand that an interface browser is coming, this is really needed badly!

Posted: Sun Oct 19, 2003 3:08 pm
by aXend
I had most of these questions myself. After some troubles I found the solution. The residents can be found at cvs.purebasic.com
You actually can use ActiveX from Purebasic. See my example in this post:
viewtopic.php?t=7902

Another examples in the code below. I found the CLSID and the GUID with the OLE-COM Object Viewer that comes with the Win32 SDK, but you can also download it from other sites. I figured out the Interface code by looking into the interface description in the Object Viewer.

Code: Select all

; Test createobject with Ximport and Xexport

; IetImportStd interface definition
;
Interface IetImportStd
  QueryInterface(a.l, b.l)
  AddRef()
  Release()
  GetTypeInfoCount(a.l)
  GetTypeInfo(a.l, b.l, c.l)
  GetIDsOfNames(a.l, b.l, c.l, d.l, e.l)
  Invoke(a.l, b.l, c.l, d.l, e.l, f.l, g.l, h.l)
  Run()
  get_MapFile(a.l)
  put_MapFile(a.l)
  get_ImportFile(a.l)
  put_ImportFile(a.l)
  get_RecordCount(a.l)
  put_RecordCount(a.l)
  get_ImportData(a.l)
  put_ImportData(a.l)
EndInterface


; IetExportStd interface definition
;
Interface IetExportStd 
  QueryInterface(a.l, b.l)
  AddRef()
  Release()
  GetTypeInfoCount(a.l)
  GetTypeInfo(a.l, b.l, c.l)
  GetIDsOfNames(a.l, b.l, c.l, d.l, e.l)
  Invoke(a.l, b.l, c.l, d.l, e.l, f.l, g.l, h.l)
  get_MapFile(a.l)
  put_MapFile(a.l)
  get_ExportFile(a.l)
  put_ExportFile(a.l)
  get_ExportData(a.l)
  put_ExportData(a.l)
  get_RecordCount(a.l)
  put_RecordCount(a.l)
  Run()
EndInterface


Importmap.s = "c:\mijn documenten\pb\test\books.imp"
Importfile.s = "c:\mijn documenten\pb\test\books_imp.xml"
Exportmap.s = "c:\mijn documenten\pb\test\books.exp"
Exportfile.s = "c:\mijn documenten\pb\test\books_exp.xml"
count_out.l

Enumeration
  #Importmap
  #Importfile
  #Exportmap
  #Exportfile
EndEnumeration

Procedure.s ByteStr(pointer.l)
  strlen.w = WideCharToMultiByte_(#CP_ACP, 0, pointer, -1, 0, 0 , 0, 0)
  string.s = Space(strlen)
  If strlen <> 0
    newlen.w = WideCharToMultiByte_(#CP_ACP, 0, pointer, -1, @string, strlen , 0, 0)
  EndIf
  ProcedureReturn string
EndProcedure

Procedure.l WideStr(pointer.l, mem.l)
  widelen.w = 2*Len(PeekS(pointer))+2
  widebuf.l = AllocateMemory(mem, widelen)
  longlen.w = MultiByteToWideChar_(#CP_ACP,0,pointer,-1,widebuf,widelen)
  ProcedureReturn widebuf
EndProcedure

CoInitialize_(0) 

If CoCreateInstance_(?CLSID_etImportStd,0,1,?IID_IetImportStd,@oImport.IetImportStd)=0 
  oImport\put_ImportFile(WideStr(@Importfile,#Importfile))
  oImport\put_MapFile(WideStr(@Importmap,#Importmap))
  oImport\Run()
  oImport\get_RecordCount(@count_out)
  MessageRequester("PureBasic - Ximport", "There are "+Str(count_out)+" records added")
  oImport\Release()
Else
  MessageRequester("Warning:","Couldn't init Ximport",0)
EndIf 

If CoCreateInstance_(?CLSID_etExportStd,0,1,?IID_IetExportStd,@oExport.IetExportStd)=0 
  oExport\put_ExportFile(WideStr(@Exportfile,#Exportfile))
  oExport\put_MapFile(WideStr(@Exportmap,#Exportmap))
  oExport\Run()
  oExport\get_RecordCount(@count_out)
  MessageRequester("PureBasic - Xexport", "There are "+Str(count_out)+" records added")
  oExport\Release()
Else
  MessageRequester("Warning:","Couldn't init Xexport",0)
EndIf 

CoUninitialize_()

End 

DataSection 
  CLSID_etImportStd:  ; {7A0D97D7-E9D1-478B-A99D-ED7027E566A2}
    Data.l $7A0D97D7
    Data.w $E9D1,$478B
    Data.b $A9,$9D,$ED,$70,$27,$E5,$66,$A2

  IID_IetImportStd:   ; {6691FB29-63F5-4133-937F-28B7B181D6F6}
    Data.l $6691FB29
    Data.w $63F5,$4133
    Data.b $93,$7F,$28,$B7,$B1,$81,$D6,$F6

  CLSID_etExportStd:  ; {489AA9D0-3D67-11D5-A56C-0004AC9B6CD1}
    Data.l $489AA9D0
    Data.w $3D67,$11D5
    Data.b $A5,$6C,$00,$04,$AC,$9B,$6C,$D1

  IID_IetExportStd:   ; {489AA9CF-3D67-11D5-A56C-0004AC9B6CD1}
    Data.l $489AA9CF
    Data.w $3D67,$11D5
    Data.b $A5,$6C,$00,$04,$AC,$9B,$6C,$D1
EndDataSection 
I hope this helps.

Posted: Fri Apr 28, 2006 11:33 am
by dmoc
Posted a few years ago so not sure if it helps but <this post> shows code to get the clsid.

Posted: Sat Apr 29, 2006 7:33 pm
by akj
aXend:
When I run your program with PB4B11 I get a warning dialogue box saying "Couldn't init Ximport". On further analysis, I discovered the error from CoCreateInstance_() has a value of #REGDB_E_CLASSNOTREG .
Would you please explain precisely what I should do to eliminate this warning message?