Solved

vb6 dll and class modules

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

772 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