Solved

vb6 dll and class modules

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

717 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