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"));
}
LVL 4
astankovicAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
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.
jkrCommented:
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.)"
astankovicAuthor Commented:
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'
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

jkrCommented:
>>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)
astankovicAuthor Commented:
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_)
jkrCommented:
>>I posted the header file above

Sorry :o)

Then, the easiest way would be to change it to read

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

extern WINLOGONDLL_API int nWinlogonDLL;

#ifdef __cplusplus
extern "C" {
#endif
WINLOGONDLL_API VOID WLEventLock (PWLX_MPR_NOTIFY_INFO);
WINLOGONDLL_API VOID WLEventUnLock (PWLX_MPR_NOTIFY_INFO);
WINLOGONDLL_API int GetNumber();
#ifdef __cplusplus
}
#endif

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
astankovicAuthor Commented:
That did the trick! Thanks a lot.
jkrCommented:
You're welcome :o)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.