Solved

C++ DLL

Posted on 2003-12-10
8
1,084 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
  • 5
  • 3
8 Comments
 
LVL 86

Expert Comment

by:jkr
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 86

Expert Comment

by:jkr
Comment Utility
>>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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 4

Author Comment

by:astankovic
Comment Utility
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
Comment Utility
>>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
Comment Utility
That did the trick! Thanks a lot.
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
You're welcome :o)
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now