Many thanks for giving it a shot. After fooling around with
pbres.exe, I found I had to first make it an rc file, run rc.exe on that,
then run pbres.exe on the .res file to get the .pbr file. Also,
I had to remove the #include resource.h line to get rc.exe
to compile the resource.
Now, after registering the dll, VB shows it in its list of
references, intellisense shows it but As New will not
include the class.
Looks like someone from PB would show us how to do this.
Announcement
Collapse
No announcement yet.
Creating An ActiveX DLL
Collapse
X
-
Hi Norm
I can get this code to compile OK, and register OK, but when
I try to set a reference to the dll in VB6 I get an error:
"Error in loading dll"
Also, trying to use CreateObject in VB6 results in the
"Can't create ActiveX..."
Any thoughts?
Although you do not have to necessarily unregister your dll it would be a good idea to so you have a clean slate to start with, and then make the following changes
As a VB-Refugee I too am starting out with COM mixed with VB (just so I have something familiar to work with and not get lost chasing my tail in another language that I do NOT know)
Anyways the following should give you a leg up on the problem.
Your Code.bas
Code:COMPILE DLL #DIM ALL '*** ADD THESE LINES #COM TLIB ON '*** 1.) Comment out your resource the 1st time compile to create your Tlib '*** 2.) Compile your resource '*** 3.) Uncomment the 2nd compile to get your resource into your dll #RESOURCE "ComServer.pbr" 'Include TLB in resource '*** END ADDED LINES #COM NAME "MyAX", 1.0 'copied from the help files $MyClassGuid = GUID$("{00000099-0000-0000-0000-000000000008}") $MyIfaceGuid = GUID$("{00000099-0000-0000-0000-000000000009}") #INCLUDE "Win32API.inc" GLOBAL ghInstance AS DWORD FUNCTION LIBMAIN (BYVAL hInstance AS LONG, _ BYVAL fwdReason AS LONG, _ BYVAL lpvReserved AS LONG) AS LONG SELECT CASE fwdReason CASE %DLL_PROCESS_ATTACH ghInstance = hInstance FUNCTION = 1 'success! CASE %DLL_PROCESS_DETACH FUNCTION = 1 'success! CASE %DLL_THREAD_ATTACH FUNCTION = 1 'success! CASE %DLL_THREAD_DETACH FUNCTION = 1 'success! END SELECT END FUNCTION CLASS MyClass $MyClassGuid AS COM INTERFACE MyInterface $MyIfaceGuid INHERIT IUNKNOWN METHOD Method1() AS LONG 'very simple method for testing METHOD=10 END METHOD END INTERFACE END CLASS
ComServer.rc
Code:#include "resource.h" //<--- Typical Resource Call 1 typelib "Pb9NormCookCom.tlb" //<--- Unsure about this yet, but researching
Form1.frm
Code:Public MyTest As MyAX.MYCLASS Private Sub Command1_Click() 'Set MyTest = New my Set MyTest = CreateObject("MyClass") MyTest.METHOD1 Set MyTest = Nothing End Sub
I am working on more advanced ideas, but gotten stuck myself so I know what you must be going through.
Leave a comment:
-
-
Creating An ActiveX DLL
I can get this code to compile OK, and register OK, but when
I try to set a reference to the dll in VB6 I get an error:
"Error in loading dll"
Also, trying to use CreateObject in VB6 results in the
"Can't create ActiveX..."
Any thoughts?
Code:#COMPILE DLL #DIM ALL #COM NAME "MyAX", 1.0 'copied from the help files $MyClassGuid = GUID$("{00000099-0000-0000-0000-000000000008}") $MyIfaceGuid = GUID$("{00000099-0000-0000-0000-000000000009}") #INCLUDE "Win32API.inc" GLOBAL ghInstance AS DWORD FUNCTION LIBMAIN (BYVAL hInstance AS LONG, _ BYVAL fwdReason AS LONG, _ BYVAL lpvReserved AS LONG) AS LONG SELECT CASE fwdReason CASE %DLL_PROCESS_ATTACH ghInstance = hInstance FUNCTION = 1 'success! CASE %DLL_PROCESS_DETACH FUNCTION = 1 'success! CASE %DLL_THREAD_ATTACH FUNCTION = 1 'success! CASE %DLL_THREAD_DETACH FUNCTION = 1 'success! END SELECT END FUNCTION CLASS MyClass $MyClassGuid AS COM INTERFACE MyInterface $MyIfaceGuid INHERIT IUNKNOWN METHOD Method1() AS LONG 'very simple method for testing METHOD=10 END METHOD END INTERFACE END CLASS
Tags: None
-
Leave a comment: