Solved

vb6 dll and class modules

Posted on 2007-03-22
2
562 Views
Last Modified: 2009-07-29
OK, i'm trying to make a vb .dll which is going to be loaded in a c++ app.

Code for dll looks like:

Public Const DLL_PROCESS_DETACH = 0
Public Const DLL_PROCESS_ATTACH = 1
Public Const DLL_THREAD_ATTACH = 2
Public Const DLL_THREAD_DETACH = 3

Public eventHandler As clsINIMiddleWareDll

Public Function DllMain(hInst As Long, fdwReason As Long, lpvReserved As Long) As Boolean
   Select Case fdwReason
      Case DLL_PROCESS_DETACH
         ' No per-process cleanup needed
      Case DLL_PROCESS_ATTACH
         DllMain = True
      Case DLL_THREAD_ATTACH
         ' No per-thread initialization needed
      Case DLL_THREAD_DETACH
         ' No per-thread cleanup needed
   End Select
    Set eventHandler = New clsINIMiddleWareDll
End Function

Public Function Increment(ByVal var As Integer) As Integer
   If Not IsNumeric(var) Then Err.Raise 5
 
   '' IF I REMOVE THE FOLLOWING LINE, IT WORKS FINE
   eventHandler.IMAppInit '' does nothing (function is empty)

   Increment = var + 1
 
End Function

I use the instructions found here:
http://www.windowsdevcenter.com/pub/a/windows/2005/04/26/create_dll.html?page=1 

to transform this dll from an activex dll to a standard windows dll.


C++ code:
short (__stdcall *Increment)(short i);
hinst_MWLib = LoadLibrary("<path to dll>");

if (hinst_MWLib != NULL) {
   Increment = (short(__stdcall *)(short)) GetProcAddress(hinst_MWLib,"Increment");

   // If the function address is valid, call the function.
   if (NULL != Increment)
   {
             int res = Increment(31);
             char* buf = new char[256];
             sprintf(buf, "hello world %d", res);
             AfxMessageBox(buf);
   }
}

Now, the above code works great but if i try to instantiate a class and call a method from it... i get access denied.
    set eventHandler = new SomeClass '' <--- can be any class
    eventHandler.IMAppInit '' does nothing (function is empty) '' <--- when trying to call this the dll errors out w/ 0xC00000005: Access Violation

What am i doing wrong?


What am i doing wrong?
0
Comment
Question by:bobbit31
2 Comments
 
LVL 18

Author Comment

by:bobbit31
ID: 18777168
p.s. this is what my DEF file looks like

NAME INI_MiddleWare
LIBRARY INI_MiddleWare
DESCRIPTION "INI Chat MiddleWare for War Rock Chat"
EXPORTS
      DllMain @1
        Increment @2
        Decrement @3
        Square @4

*** before you yell at me saying "vb6 doesn't support def files"... please see the link posted above regarding activex to normal windows dll... thanks :)
0
 
LVL 13

Accepted Solution

by:
Mark_FreeSoftware earned 500 total points
ID: 18786161

and where exactly do you create and call that class?

if it is in the c++ program,
your out of luck, the vb dll isnt an activex dll anymore
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now