473,655 Members | 3,072 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

'Unresolved External' when calling unmanaged DLL from managed Windows Forms executable

Greetings!

I'm a newbie in Visual C++ .NET (have programmed in Borland C++
and Builder for long) and I am trying to do a very simple thing,
but I'm stuck.

I created an (unmanaged) DLL project with a sample function, and
tried to call it from a ".NET Forms" project. All I get are
"Unresolved External" errors from the Linker!

When I try to call the same functions from a "Pure Win32" or a
Console Application, everything works well!

What could be happening? I'm sure it's something very trivial
and silly, but I'm stuck!

What I've done so far:

- Created the DLL, using Visual Studio default macros
- Exported the class contained in the DLL that I want to use.
- Compiled the DLL, OK
- Created a Windows Forms project, with one button that tried to
instantiate the class defined in the DLL and call its function.

Configurations for the Windows Forms Executable Project:
C/C++
General - Additional Include Directories: ..\DrawDll
Linker
General - Additional Library Directories: ..\DrawDll\Rele ase
Input - Additional Dependencies:
...\DrawDll\Rel ease\DrawDll.li b

I have 2 projects in the solution, each one on its own directory.

That's all that was necessary for the Console AND for the Win32
versions to work! However, on this project I'm getting:

Form1.obj : error LNK2001: unresolved external symbol "public:
__thiscall Project::CDrawD ll::CDrawDll(vo id)"
(??0CDrawDll@Pr oject@@$$FQAE@X Z)
Form1.obj : error LNK2001: unresolved external symbol "public: void
__thiscall Project::CDrawD ll::MyMethod(vo id)"
(?MyMethod@CDra wDll@Project@@$ $FQAEXXZ)

Any clues?

Here are the files being used:

DrawDll.h
#ifdef DRAWDLL_EXPORTS
#define DRAWDLL_API __declspec(dlle xport)
#else
#define DRAWDLL_API __declspec(dlli mport)
#endif

// This class is exported from the DrawDll.dll
class DRAWDLL_API CDrawDll {
public:
CDrawDll(void);
void MyMethod(void);

};

DrawDll.cpp
#include "stdafx.h"
#include "DrawDll.h"
#include <stdio.h>

BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_c all,
LPVOID lpReserved
)
{
switch (ul_reason_for_ call)
{
case DLL_PROCESS_ATT ACH:
case DLL_THREAD_ATTA CH:
case DLL_THREAD_DETA CH:
case DLL_PROCESS_DET ACH:
break;
}
return TRUE;
}

void CDrawDll::MyMet hod(void)
{
OutputDebugStri ng("It Worked!");
}
The Project.cpp and Project.h files are just the default
"Windows Forms Application (.NET)" generated files, plus
the code to try and run the DLL:

Form1.h
#include <windows.h>
#include <stdio.h>
#include "DrawDll.h"

public __gc class Form1 : public System::Windows ::Forms::Form

....

private: System::Void button1_Click(S ystem::Object * sender,
System::EventAr gs * e)
{

CDrawDll lala;
lala.MyMethod() ;
}

Form1.cpp
#include "stdafx.h"
#include "Form1.h"
#include <windows.h>

using namespace Project;

int APIENTRY _tWinMain(HINST ANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
System::Threadi ng::Thread::Cur rentThread->ApartmentSta te =
System::Threadi ng::ApartmentSt ate::STA;
Application::Ru n(new Form1());
return 0;
}

Thanks for any help!
Nov 17 '05 #1
3 2708
These two titles in the docs might help.

"Accessing C++ Code from .NET Framework Objects"
http://msdn.microsoft.com/library/de...orkobjects.asp

"Platform Invocation Services"
http://msdn.microsoft.com/library/de...onServices.asp
Nov 17 '05 #2
Greetings! Thank you very much for some reply. I wonder if my question is
so obvious nobody cared to answer or if, theoretically, I was doing things
right and it should be working, so things are more complicated!

As said on the 2nd link,
"Platform Invocation Services"
http://msdn.microsoft.com/library/de...onServices.asp
, *An important and unique feature of Managed Extensions for C++ is that you
can use unmanaged APIs directly. Data marshaling is handled automatically.
If you do not require customized data marshaling, you do not need to use
PInvoke. *
This is what I actually want to do. I'm using Managed Extensions for C++! My
Executable project is in C++, not on C#, Visual Basic or
any other language. Should the marshaling still be necessary?

*Advantages of IJW There is no need to write DLLImport attribute
declarations for the unmanaged APIs the program uses. Just include the
header file and link with the import library.

*

There, I've included the header file and included the .LIB file. Isn't that
what I am really supposed to do? Am I doing something wrong?

I checked the .DLL file with depends.exe and found out the decorated name
for the function is

'?MyMethod@CDra wDll@@QAEXXZ,

but the linker error mentions

"public: void __thiscall Project::CDrawD ll::MyMethod(vo id)"
(?MyMethod@CDra wDll@Project@@$ $FQAEXXZ)'

Could this @Project@ reference be the reason why it isn't resolving the
symbol? "Project" is the name I gave for the 'Windows Forms Executable"
project, that tries to use the DLL.

Thanks for any help!

Gustavo
Nov 17 '05 #3
I'm in the same boat as you. I'm just beginning to learn C++ with extension,
and the first thing I tried is to call a C++ class which is located in a
DLL. I looked high and low and found no help in how to do so. That's
probably why one of those links limits itself to directly calling functions
in a DLL. I finally came to the conclusion that it is not possible, which is
probably why the other link suggested wrapping the C++ class, which is what
I am finally now doing. As an aside, in case it is helpful, my wrapping
class only exposes managed types, e.g., Int32, IntPointer, etc. I am
handling any necessary marshalling with my own code.
Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4121
by: David Kantowitz | last post by:
I am trying to wrap a native-C++ DLL in managed C++, to use in a .NET project. The native code is compiled into a DLL, and I have created a .def file that exports the mangled names of the symbols I am going to use from the wrapper library. The wrapper library has the code written that uses the native classes, and wraps them to present an equivalent of their interface for .NET.
8
4158
by: Scott Allen | last post by:
Hello, I'm new to C++ development and I'm trying out figure out the cause of an 'unresolved external symbol' error that I'm receiving when compiling. Here is some history on what I'm doing: I have an existing VC++ project that mostly just reads a SQL Server database does some work on the data and insert the results into another table. I have the need to incorproate some functionality from a certain dll named cedb300.dll. cedb300.dll...
1
8402
by: Aravind | last post by:
we have two files: 1. rc4.c (defines one function "create_pin()") 2. MyImpl.c(calling the function "create_pin()"),This implements JNI method. 1.When I am trying to create .dll file with one file rc4.obj(rc4.c),it is creating the .dll file without any error. Command : ILINK32 rc4.obj 2.But,when we are trying to create .dll file with two .obj files with following errors.
3
3523
by: Kevin Burton | last post by:
I am trying to use managed C++ but I am getting the following link errors: Metadata file 'D:\Projects\Visa\AddressVerification\AddressVerificat ionTest\bin\Debug\AddressVerificationInterface.dll' could not be found AddressVerificationInterface error LNK2001: unresolved external symbol "void * __cdecl operator new(unsigned int)" (??2@$$FYAPAXI@Z)
0
1347
by: Jonathan DeCarlo | last post by:
Everytime I try to instantiate an instance of an unmanaged C++ class inside of a managed C++ class, I get the following two linker errors: TestDll2 error LNK2001: unresolved external symbol "void * __cdecl operator new(unsigned int)" (??2@$$FYAPAXI@Z) TestDll2 error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" (??3@$$FYAXPAX@Z)
0
2929
by: Roland | last post by:
Hi, ultimately I want to call some unmanaged C++ class that contains some DirectShow code of mine from my C# classes, but for the time being I'd be happy if I could get this to build! I have read the other topics on the same problem here on the groups but haven't found the solution to my problem yet. I have written a managed C++ wrapper class called MDirectShowHandler. This currently wraps only the constructor and destructor calls (see
6
362
by: AK | last post by:
I have a .NET application that compiles but has a problem during linking : error LNK2001: unresolved external symbol "int __cdecl ReadLn(struct _iobuf *,char * const)" (?ReadLn@@$$FYAHPAU_iobuf@@QAD@Z) The ReadLn function prototype is defined in a header file & is called in another header file. My compiler options are set to /Gd & /Tp. If I do not call the function (& just have it's prototype declared),
6
3359
by: guxu | last post by:
I have a managed C++ code which calls some methods in unmanaged C++ DLL. In my unmanaged DLL, I have a PROTECTED virutal function in a base class and derived class has a PRIVATE function which overrides the virutal one in the base. In my managed class, I have the following private: CUnmanaged __nogc* m_pUnManaged
8
3736
by: Joe Withawk | last post by:
I have a solution consisting of a c# project as win application and a c++ project as classlibrary. Both are .net 2.0 The classlibrary handles some loading of quicktime movies, but that should not be relevant. On my development machine I build the exe and dll and run the exe which has a reference to the dll. At some point it uses featured in the dll. This works fine. Then I copy my exe and dll to the target system and when the featured...
0
8380
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8816
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8710
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8497
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7310
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5627
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1598
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.