Solved

C++ DLL

Posted on 2003-12-10
8
1,098 Views
Last Modified: 2007-12-19
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
Comment
Question by:astankovic
[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
  • 5
  • 3
8 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 9914133
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
 
LVL 86

Expert Comment

by:jkr
ID: 9914244
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
 
LVL 4

Author Comment

by:astankovic
ID: 9914769
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
Independent Software Vendors: 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!

 
LVL 86

Expert Comment

by:jkr
ID: 9914790
>>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
 
LVL 4

Author Comment

by:astankovic
ID: 9914853
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
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 9914891
>>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
 
LVL 4

Author Comment

by:astankovic
ID: 9915201
That did the trick! Thanks a lot.
0
 
LVL 86

Expert Comment

by:jkr
ID: 9915215
You're welcome :o)
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

751 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