Solved

vb6 dll and class modules

Posted on 2007-03-22
2
560 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

708 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

20 Experts available now in Live!

Get 1:1 Help Now