Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1103
  • Last Modified:

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"));
}
0
astankovic
Asked:
astankovic
  • 5
  • 3
1 Solution
 
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.
0
 
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.)"
0
 
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'
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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)
0
 
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_)
0
 
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
0
 
astankovicAuthor Commented:
That did the trick! Thanks a lot.
0
 
jkrCommented:
You're welcome :o)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now