Solved

vb6 dll and class modules

Posted on 2007-03-22
2
567 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What is sub-make ? 2 102
MS Access 03, TransferText, decimal places 8 92
IF ELSE Statement in Excel Macro VBA 16 98
Macro problems with Excel file 6 52
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…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

732 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