Comlib source

Developed or developing a new product in PureBasic? Tell the world about it.
aXend
Enthusiast
Enthusiast
Posts: 103
Joined: Tue Oct 07, 2003 1:21 pm
Location: Netherlands

Comlib source

Post by aXend »

I'm sorry I don't have the time to update Comlib. I will publish the source here so you can improve it. I'm somehow very sure that you will! :wink:
Good luck to you...

Code: Select all

Enumeration
  #CLSCTX_INPROC_SERVER  = 1
  #CLSCTX_INPROC_HANDLER = 2
  #CLSCTX_LOCAL_SERVER   = 4 
  #CLSCTX_REMOTE_SERVER  = 16
  #CLSCTX_SERVER = (#CLSCTX_INPROC_SERVER | #CLSCTX_LOCAL_SERVER | #CLSCTX_REMOTE_SERVER)
EndEnumeration

Structure TYPEATTR 
  guid.GUID 
  lcid.l 
  dwReserved.l 
  memidConstructor.l 
  memidDestructor.l 
  lpstrSchema.l 
  cbSizeInstance.l 
  typekind.l 
  cFuncs.w 
  cVars.w 
  cImplTypes.w 
  cbSizeVft.w 
  cbAlignment.w 
  wTypeFlags.w 
  wMajorVerNum.w 
  wMinorVerNum.w 
  tdescAlias.l 
  idldescType.l 
EndStructure 

ProcedureDLL.s Uni2Ansi(unicodestr.l) ; Converts Unicode to normal (Ansi) string
  lenA = WideCharToMultiByte_(#CP_ACP, 0, unicodestr, -1, 0, 0, 0, 0);
  ansistr.s = Space(lenA)
  If (lenA > 0)
    WideCharToMultiByte_(#CP_ACP, 0, unicodestr, -1, @ansistr, lenA, 0, 0);
  EndIf
  ProcedureReturn ansistr
EndProcedure

ProcedureDLL.l Ansi2Uni(ansistr.s) ; Converts normal (Ansi) string to Unicode
  lenA.l = Len(ansistr)
  lenW = MultiByteToWideChar_(#CP_ACP, 0, ansistr, lenA, 0, 0)
  If (lenW > 0) ; Check whether conversion was successful
    unicodestr = SysAllocStringLen_(0, lenW)
    MultiByteToWideChar_(#CP_ACP, 0, ansistr, lenA, unicodestr, lenW)
    result = unicodestr
    ProcedureReturn result
  Else 
    ProcedureReturn 0
  EndIf
EndProcedure

ProcedureDLL.l CreateObject(ProgID.s) ; Creates COM object from ProgID

  err.l = CLSIDFromProgID_(Ansi2Uni(ProgID), @CLSID.GUID)
  If err <> #S_OK
    SetErrorNumber(err)
    End
  EndIf

  err.l = CoCreateInstance_(CLSID,0,#CLSCTX_SERVER,?IID_IDispatch,@oDispatch.IDispatch)
  If err <> #S_OK
    SetErrorNumber(err)
    End
  EndIf

  If oDispatch\GetTypeInfo(0,lcid,@oDispTypeInfo.ITypeInfo) = #S_OK
    If oDispTypeInfo\GetTypeAttr(@aTypeAttributes.l) = #S_OK
      *oTypeAttributes.TYPEATTR=aTypeAttributes
      IID_OBJECT = *oTypeAttributes\guid
      oDispTypeInfo\ReleaseTypeAttr(aTypeAttributes)
    EndIf
    oDispTypeInfo\Release()
  EndIf

  err.l = oDispatch\QueryInterface(IID_OBJECT,@object.l)
  If err <> #S_OK
    oDispatch\Release()
    SetErrorNumber(err)
    End
  EndIf
  oDispatch\Release()

  ProcedureReturn object
EndProcedure

ProcedureDLL ReleaseObject(object.l) ; Releases Object from memory
  *object.IUnknown = object
  *object\Release()
EndProcedure

ProcedureDLL COMLIB_Init()
  CoInitialize_(#Null) 
EndProcedure

ProcedureDLL COMLIB_End()
  CoUninitialize_()  
EndProcedure

DataSection
  IID_IDispatch:
  Data.l $00020400
  Data.w $0000, $0000
  Data.b $C0,$00,$00,$00,$00,$00,$00,$46
EndDataSection
  
DataSection
  IID_IUnknown:
  Data.l $00000000
  Data.w $0000, $0000
  Data.b $C0,$00,$00,$00,$00,$00,$00,$46
EndDataSection
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post by GedB »

Thanks Axend, 8)

Is the source for the interface extractor available too?
User avatar
Kiffi
Addict
Addict
Posts: 1485
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Post by Kiffi »

Hello aXend,

thank you for sharing your code!

Greetings ... Kiffi
User avatar
SimpleMind
Enthusiast
Enthusiast
Posts: 112
Joined: Sun May 18, 2003 12:40 pm
Location: Netherlands

Comlib source

Post by SimpleMind »

Thanks, aXend.
Give me books, fruit, french wine, fine weather and a little music.
John Keats
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

I recompiled this library from the given source.

You can download a PB4.02 COMLIB UserLibrary here :
UserLib_PB40_COMLIB.zip

Caution:
With the given source, the CreateObject() function is NOT unicode compatible.
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

oh sorry i wasn't aware :oops:

and i didn't know that myFunction_Unicode() works with tailbite.
good to know.
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

@flype
no problem, many people doesn't see my libs :wink:

// edit:
by the way, i have found a small bug in my lib, updated!
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Post Reply