Link to home
Start Free TrialLog in
Avatar of astankovic
astankovic

asked on

C++ DLL

I've never created an C++ DLL before... so i need some help.
The dll compiles without errors or warnings, but when i try to import in in VB6 app, i get the error "no entry point for [function name]"
What am i doing wrong?

The code is trait from the wizard and msdn sample.

Thanks!

Here is the source

In VB6 app
--------------------------
Declare Sub WLEventLock Lib "C:\WinLogonDLL.dll" (pNprNotifyInfo As PWLX_MPR_NOTIFY_INFO)
Call WLEventLock(p)

include file
-----------------------------
#ifdef WINLOGONDLL_EXPORTS
#define WINLOGONDLL_API __declspec(dllexport)
#else
#define WINLOGONDLL_API __declspec(dllimport)
#endif


extern WINLOGONDLL_API int nWinlogonDLL;

WINLOGONDLL_API VOID WLEventLock (PWLX_MPR_NOTIFY_INFO);
WINLOGONDLL_API VOID WLEventUnLock (PWLX_MPR_NOTIFY_INFO);

source file
------------------------------------------
#include "stdafx.h"
#include "WinlogonDLL.h"

BOOL APIENTRY DllMain( HANDLE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                               )
{
    switch (ul_reason_for_call)
      {
            case DLL_PROCESS_ATTACH:
            case DLL_THREAD_ATTACH:
            case DLL_THREAD_DETACH:
            case DLL_PROCESS_DETACH:
                  break;
    }
    return TRUE;
}


WINLOGONDLL_API VOID WLEventLock (PWLX_MPR_NOTIFY_INFO pInfo)
{
    OutputDebugString (TEXT("NOTIFY:  Entering WLEventLock.\r\n"));
}

WINLOGONDLL_API VOID WLEventUnLock (PWLX_MPR_NOTIFY_INFO pInfo)
{
    OutputDebugString (TEXT("NOTIFY:  Entering WLEventUnLock.\r\n"));
}
Avatar of jkr
jkr
Flag of Germany image

You are probably a victim of C++ name mangling - export the functions as

#ifdef __cplusplus
extern "C"
#endif
WINLOGONDLL_API VOID WLEventLock (PWLX_MPR_NOTIFY_INFO pInfo)
{
   OutputDebugString (TEXT("NOTIFY:  Entering WLEventLock.\r\n"));
}

#ifdef __cplusplus
extern "C"
#endif
WINLOGONDLL_API VOID WLEventUnLock (PWLX_MPR_NOTIFY_INFO pInfo)
{
   OutputDebugString (TEXT("NOTIFY:  Entering WLEventUnLock.\r\n"));
}

to turn off that behaviour.
BTW, a good explanation on the whole subject can be found at http://www.microsoft.com/msj/archive/S330.aspx

"The second fundamental truth is that compilers change symbol names behind your back. For example, C compilers prepend an underbar to the symbol name as it appears in the OBJ file. Thus, function Foo in A.C appears as the public symbol _Foo in A.OBJ. Another example is when you use C++; the compiler takes the function name and adds additional information about the function's parameters. In Visual C++, the function "void Foo(int i)" becomes "?Foo@@YAXH@Z". This renaming is called mangling or decorating, and allows the linker to differentiate between overloaded functions. (Overloaded functions are functions that have the same name, but different parameter lists. With this in mind, you can see how the linker deals with overloaded C++ functions.)"
Avatar of astankovic
astankovic

ASKER

Thanks for your post. I added

#ifdef __cplusplus
extern "C"
#endif
before functions but I'm now getting this error for both functions:

error C2732: linkage specification contradicts earlier specification for 'WLEventLock'
>>error C2732: linkage specification contradicts earlier specification for 'WLEventLock'

Could you post the header file? You need to add that there in the 1st place instead of the implementation file. I was under the impresseion that this was all your code :o)
I posted the header file above, but here it is again:

Thanks for looking into this.
WinlogonDll.h
----------------------------------
// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the WINLOGONDLL_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// WINLOGONDLL_API functions as being imported from a DLL, wheras this DLL sees symbols
// defined with this macro as being exported.
#ifdef WINLOGONDLL_EXPORTS
#define WINLOGONDLL_API __declspec(dllexport)
#else
#define WINLOGONDLL_API __declspec(dllimport)
#endif


extern WINLOGONDLL_API int nWinlogonDLL;

WINLOGONDLL_API VOID WLEventLock (PWLX_MPR_NOTIFY_INFO);
WINLOGONDLL_API VOID WLEventUnLock (PWLX_MPR_NOTIFY_INFO);

WINLOGONDLL_API int GetNumber();


stdafx.h
-----------------------------
// stdafx.h : include file for standard system include files,
//  or project specific include files that are used frequently, but
//      are changed infrequently
//

#if !defined(AFX_STDAFX_H__C87D2766_9CFA_4E9D_B976_668480819DDF__INCLUDED_)
#define AFX_STDAFX_H__C87D2766_9CFA_4E9D_B976_668480819DDF__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000


// Insert your headers here
#define WIN32_LEAN_AND_MEAN            // Exclude rarely-used stuff from Windows headers

#include <windows.h>
#include <winwlx.h>

// TODO: reference additional headers your program requires here

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_STDAFX_H__C87D2766_9CFA_4E9D_B976_668480819DDF__INCLUDED_)
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That did the trick! Thanks a lot.
You're welcome :o)