Problems to see a DLL written in Visual C++ 
Author Message
 Problems to see a DLL written in Visual C++

I have got some problems to see, from a program written in VB, a DLL
written in Visual C++. I have DECLAREd all functions and subs I will
ise, but, at run-time, I get a message saying those functions are not
found.

The DLL is written in VC++, as explained, and works properly when
invoked from another C++ program.

Do I need to register in some way (other than DECLARE) a DLL's
functions? Do I have to include them in any registry or Windows NT
system file? What is exactly the problem?

Any help would be welcomed



Tue, 31 Aug 1999 03:00:00 GMT  
 Problems to see a DLL written in Visual C++


Mar 1997 14:10:51 GMT):

Quote:
>I have got some problems to see, from a program written in VB, a DLL
>written in Visual C++. I have DECLAREd all functions and subs I will
>ise, but, at run-time, I get a message saying those functions are not
>found.

>The DLL is written in VC++, as explained, and works properly when
>invoked from another C++ program.

>Do I need to register in some way (other than DECLARE) a DLL's
>functions? Do I have to include them in any registry or Windows NT
>system file? What is exactly the problem?

You either got declarations wrong or called a 16bit-DLL from
VB4-32 (which is impossible).

Mathias Schiffer



Fri, 03 Sep 1999 03:00:00 GMT  
 Problems to see a DLL written in Visual C++

Quote:


>Mar 1997 14:10:51 GMT):

>>I have got some problems to see, from a program written in VB, a DLL
>>written in Visual C++. I have DECLAREd all functions and subs I will
>>ise, but, at run-time, I get a message saying those functions are not
>>found.

>>The DLL is written in VC++, as explained, and works properly when
>>invoked from another C++ program.

>>Do I need to register in some way (other than DECLARE) a DLL's
>>functions? Do I have to include them in any registry or Windows NT
>>system file? What is exactly the problem?

>You either got declarations wrong or called a 16bit-DLL from
>VB4-32 (which is impossible).

>Mathias Schiffer

Most likely the DLL function names have been "mangled." Since C++ allows
function overloading (i.e., two or more functions with the same name,
differing only in the number and/or types of parameters), the compiler adds
extra characters to the function name when creating the DLL to differentiate
between potentially duplicate names.

To get around this, in the C++ program header use

        extern "C"

before the function declarations. This will ensure that no name mangling is
done.

You didn't have this problem when calling the functions from another C++
program since it understood the mangled names.

Hope this helps,

Bob



Sun, 05 Sep 1999 03:00:00 GMT  
 Problems to see a DLL written in Visual C++



Quote:
> I have got some problems to see, from a program written in VB, a DLL
> written in Visual C++. I have DECLAREd all functions and subs I will
> ise, but, at run-time, I get a message saying those functions are not
> found.

> The DLL is written in VC++, as explained, and works properly when
> invoked from another C++ program.

> Do I need to register in some way (other than DECLARE) a DLL's
> functions? Do I have to include them in any registry or Windows NT
> system file? What is exactly the problem?

> Any help would be welcomed

In your C++ header file prototyping the functions to be called by VB
did you use something like:

#ifdef __cpluscplus
extern "C"
{
#endif

..... your C function declarations

#ifdef __cplusplus

Quote:
}

#endif

If you didn't do this, it's possible that C++ compiler mangled the
routine names.

A couple of years ago I had a similar problem -- ie a DLL worked
fine with a C++ prog, but not with VB.

I you look at the MAP file for the DLL, you can easily tell if names
being mangled.

if the source code is:

... MyFunction( ...

the map file will show

... _MyFunction

if the name is NOT mangled, but left as a C function,

and will be something like


if it is treated as C++ function.



Sun, 05 Sep 1999 03:00:00 GMT  
 Problems to see a DLL written in Visual C++


Quote:
>I have got some problems to see, from a program written in VB, a DLL
>written in Visual C++. I have DECLAREd all functions and subs I will
>ise, but, at run-time, I get a message saying those functions are not
>found.

In addition to all of the other advice that you've gotten about function
name mangling and C++, there's another catch. Typically, your function is
going to look something like this:

    #ifdef __cplusplus
    extern "C" {
    #endif

    BOOL WINAPI MyFunction(/* Parameters */)
    {
        /* Code */
    }

    #ifdef __cplusplus
    }
    #endif

And you'll declare it something like this ...

    __declspec(dllexport) BOOL WINAPI MyFunction(/* Parameters */);

This looks all fine and wonderful, except that you'll still have problems.
Why? Because the "stdcall" convention also mangles the function name, which
is what WINAPI is defined as. To defeat this, you'll actually need to use a
DEF file (remember when Microsoft said we didn't need these any more?) and
add the function to the EXPORTS section, like this:

    LIBRARY         FUBAR32
    DESCRIPTION     'The Fubar Library (32-Bit)'
    EXPORTS
                    MyFunction

This will encourage the linker to not mangle the name of MyFunction so that
it can found either by Visual Basic, or a call to GetProcAddress().

Cheers,
Mike
----

Catalyst Development Corporation          Web:   http://www.catalyst.com



Mon, 06 Sep 1999 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Visual Basic 4.0 usage of DLLs written in Visual C++ 4.0

2. How to write Visual C++ DLL's and call them from Visual Basic

3. Visual Basic 4.0 usage of DLLs written in Visual C++ 4.0

4. A problem with ocx written in visual c++ only in vb (oca problem)

5. VB4/5 importing functions from a DLL written in Visual C++ 5

6. VB5 compiled module vs compiled DLL written in Visual C++ 5

7. Anyone seen R6025 error: Visual C++ pure virtual function call

8. Problems with DLL written in C++

9. Calling VB ActiveX DLL from Visual C++ problem

10. adapting Visual C++ dll for Visual Basic

11. How do you call a Visual C++ (DLL) function from Visual Basic

12. Calling Visual C++ 5.0 DLL Functions From Visual Basic 5.0

 

 
Powered by phpBB® Forum Software