Theos PowerBasic Museum 2017

Archive => Discussion - Legacy Software (PBWIN 9.0+/PBCC 5.0+) => Topic started by: Eros Olmi on June 19, 2010, 11:57:25 PM

Title: PB COM dll to be used in Excel
Post by: Eros Olmi on June 19, 2010, 11:57:25 PM
I'm trying to create a prototype of a COM Dll to be used in Excel (or any COM aware application)
DLL is registered in Windows.
I can browse it with PB COM Browser
I can browse it José TypeLib
I can see in Excel as programming reference but when I try to use it in Excel it GPF as soon as I instanciate a new object.

I must miss something under my nose but after hours I'm not able to find it or maybe I still need to know something.

Any help is appreciated.

Attached full project with sources, dll and VBS + Excel example.
Title: Re: PB COM dll to be used in Excel
Post by: José Roca on June 20, 2010, 12:49:05 AM
Hi Eros,

See post #15 of this thread: http://www.powerbasic.com/support/pbforums/showthread.php?t=40247&highlight=excel
Title: Re: PB COM dll to be used in Excel
Post by: Eros Olmi on June 20, 2010, 12:55:27 AM
Thanks a lot José but maybe I gave wrong indication
I'm not particualrly interested in Excel, I'm using Excel just fortesting

The above COM Dll does not work even in a simple VBS script like:
Quoteset objA = CreateObject("thinbasicx")

if IsObject(objA) = False then
  msgbox "Library not loaded"
else
  msgbox "Start sleeping"

  objA.sleep(2000)

  msgbox "End sleeping"

  set objA = Nothing
end if

CreateObject fails immediately.

I have to say I'm under Windows 7 64bit, do not know if this can justify something.

Ciao
Eros
Title: Re: PB COM dll to be used in Excel
Post by: Eros Olmi on June 20, 2010, 01:03:30 AM
Yes, under 32bit OS it seems to work.
Title: Re: PB COM dll to be used in Excel
Post by: Eros Olmi on June 20, 2010, 01:30:46 AM
Recoded a bit and updated attached file in first post.
I can confirm: under Wind 7 64Bit COM Server gives error as soon as I try to instanciate. Under 32bit it works fine
Title: Re: PB COM dll to be used in Excel
Post by: José Roca on June 20, 2010, 03:37:49 AM
 
If VBScript is 64 bit, it can't use 32-bit servers.
Title: Re: PB COM dll to be used in Excel
Post by: Mike Stefanik on June 20, 2010, 08:22:18 AM
There was a discussion about mixing 32-bit and 64-bit code over in the PB forums, such as here (http://www.powerbasic.com/support/pbforums/showthread.php?t=43651). Bottom line, the only way to make a 32-bit COM server work with 64-bit code is it must be out-of-process (i.e.: an ActiveX EXE). A 64-bit process cannot load 32-bit code into its address space.
Title: Re: PB COM dll to be used in Excel
Post by: Eros Olmi on June 20, 2010, 10:32:13 AM
I installed AutoIt script engine 32bit and it works from VBScript 64 bit.
So I suppose because it is an ActiveX

I analysed both COM Server (AutoIt and my PB COM lib) using José TypeLib browser and, apart the use of capitals letters in COM libs created with PB, the rest is very very similar.

Anyhhow, thanks a lot.
I need to study more on this matter.

Added: it would be nice to have possibility to alias programIDs, interface names, parameters names, ... in order to have them in mixed case.
Title: Re: PB COM dll to be used in Excel
Post by: José Roca on June 20, 2010, 04:09:02 PM
Quote
I installed AutoIt script engine 32bit and it works from VBScript 64 bit.
So I suppose because it is an ActiveX

Doubtful. Maybe the AutoIt installer has installed both a 32-bit and 64-bit versions.

Quote
I analysed both COM Server (AutoIt and my PB COM lib) using José TypeLib browser and, apart the use of capitals letters in COM libs created with PB, the rest is very very similar.

The first function called when a DLL is loaded (and an OCX is a DLL with just a different extesion name) is LIBMAIN:

FUNCTION LIBMAIN(BYVAL hInstance AS DWORD, _
  BYVAL lReason AS LONG, _
  BYVAL lReserved AS LONG) AS LONG

And the first parameter, hInstance, is a DWORD in 32-bit and a QUAD in 64-bit.