473,405 Members | 2,272 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Can I create a C++ class library(DLL) and use it in C#?

Hi,

I have a few C BER coding that I would like to compile into a C++ Class
library project and then use it in my C# windows application. Can I do that
from C# using pinvoke? If not then does anyone how can I call these
functions from C#?
--
Thanks.
Aug 28 '06 #1
6 5351
I have a few C BER coding that I would like to compile into a C++ Class
library project and then use it in my C# windows application. Can I do
that
from C# using pinvoke? If not then does anyone how can I call these
functions from C#?
Hi,
You don't have to create a class library.
Simply export those functions from a dll as C functions, using a DEF file or
using __declspec(dllexport)
You can then use P/Invoke those functions in your C# application.
That would be the easiest solution.

--

Kind regards,
Bruno van Dooren
br**********************@hotmail.com
Remove only "_nos_pam"
Aug 29 '06 #2
Thank you.
"Bruno van Dooren [MVP VC++]" wrote:
I have a few C BER coding that I would like to compile into a C++ Class
library project and then use it in my C# windows application. Can I do
that
from C# using pinvoke? If not then does anyone how can I call these
functions from C#?

Hi,
You don't have to create a class library.
Simply export those functions from a dll as C functions, using a DEF file or
using __declspec(dllexport)
You can then use P/Invoke those functions in your C# application.
That would be the easiest solution.

--

Kind regards,
Bruno van Dooren
br**********************@hotmail.com
Remove only "_nos_pam"
Aug 29 '06 #3
One thing worth remembering is: you can use only declspec calling
convention....

-Shekhar
"Pucca" <Pu***@discussions.microsoft.comwrote in message
news:04**********************************@microsof t.com...
Thank you.
"Bruno van Dooren [MVP VC++]" wrote:
I have a few C BER coding that I would like to compile into a C++ Class
library project and then use it in my C# windows application. Can I do
that
from C# using pinvoke? If not then does anyone how can I call these
functions from C#?

Hi,
You don't have to create a class library.
Simply export those functions from a dll as C functions, using a DEF file
or
using __declspec(dllexport)
You can then use P/Invoke those functions in your C# application.
That would be the easiest solution.

--

Kind regards,
Bruno van Dooren
br**********************@hotmail.com
Remove only "_nos_pam"

Aug 29 '06 #4
One thing worth remembering is: you can use only declspec calling
convention....
Actually, declspec is not a calling convention. It's a declaration
specifier.
And you can use __stdcall, __fastcall or __cdecl calling convention.
Whatever is fit for your purpose.
Afaik there is no restriction on calling convention when using DllImport in
C#.

--

Kind regards,
Bruno van Dooren
br**********************@hotmail.com
Remove only "_nos_pam"
Aug 29 '06 #5
Funny you should mention the calling conventions. I'm getting LNK2019 error
when I tried to create the my C++ DLL and export it. Here is my export
statement:
#include "stdafx.h"
extern "C" DE_ERRORS __declspec(dllexport)DecodeAsnUser(Blob* pBlob,
CUserContextData *userData)
{
my code;
}
Here are my errors:
-------------------------------------------------------
Error 1 error LNK2019: unresolved external symbol "void __stdcall
_com_issue_error(long)" (?_com_issue_error@@YGXJ@Z) referenced in function
"public: class _bstr_t & __thiscall _bstr_t::operator=(char const *)"
(??4_bstr_t@@QAEAAV0@PBD@Z) UnityDecodeAsnUser.obj

Error 2 error LNK2019: unresolved external symbol "wchar_t * __stdcall
_com_util::ConvertStringToBSTR(char const *)"
(?ConvertStringToBSTR@_com_util@@YGPA_WPBD@Z) referenced in function "public:
__thiscall _bstr_t::Data_t::Data_t(char const *)"
(??0Data_t@_bstr_t@@QAE@PBD@Z) UnityDecodeAsnUser.obj

Error 3 error LNK2019: unresolved external symbol "char * __stdcall
_com_util::ConvertBSTRToString(wchar_t *)"
(?ConvertBSTRToString@_com_util@@YGPADPA_W@Z) referenced in function "public:
char const * __thiscall _bstr_t::Data_t::GetString(void)const "
(?GetString@Data_t@_bstr_t@@QBEPBDXZ) UnityDecodeAsnUser.obj

Error 4 fatal error LNK1120: 3 unresolved
externals C:\Projects\UnityDecodeAsnUser\Debug\UnityDecodeAs nUser.dll

How can I correct this Lnk error?

--
Thanks.
"Bruno van Dooren [MVP VC++]" wrote:
One thing worth remembering is: you can use only declspec calling
convention....

Actually, declspec is not a calling convention. It's a declaration
specifier.
And you can use __stdcall, __fastcall or __cdecl calling convention.
Whatever is fit for your purpose.
Afaik there is no restriction on calling convention when using DllImport in
C#.

--

Kind regards,
Bruno van Dooren
br**********************@hotmail.com
Remove only "_nos_pam"
Aug 29 '06 #6
Ok, I seem to get rid of the lnk2019 error by doing the following:
link "comsuppwd.lib" in debug AdditionalDependencies.
Link "comsuppw.lib" in release AdditionalDependencies
--
Thanks.
"Pucca" wrote:
Funny you should mention the calling conventions. I'm getting LNK2019 error
when I tried to create the my C++ DLL and export it. Here is my export
statement:
#include "stdafx.h"
extern "C" DE_ERRORS __declspec(dllexport)DecodeAsnUser(Blob* pBlob,
CUserContextData *userData)
{
my code;
}
Here are my errors:
-------------------------------------------------------
Error 1 error LNK2019: unresolved external symbol "void __stdcall
_com_issue_error(long)" (?_com_issue_error@@YGXJ@Z) referenced in function
"public: class _bstr_t & __thiscall _bstr_t::operator=(char const *)"
(??4_bstr_t@@QAEAAV0@PBD@Z) UnityDecodeAsnUser.obj

Error 2 error LNK2019: unresolved external symbol "wchar_t * __stdcall
_com_util::ConvertStringToBSTR(char const *)"
(?ConvertStringToBSTR@_com_util@@YGPA_WPBD@Z) referenced in function "public:
__thiscall _bstr_t::Data_t::Data_t(char const *)"
(??0Data_t@_bstr_t@@QAE@PBD@Z) UnityDecodeAsnUser.obj

Error 3 error LNK2019: unresolved external symbol "char * __stdcall
_com_util::ConvertBSTRToString(wchar_t *)"
(?ConvertBSTRToString@_com_util@@YGPADPA_W@Z) referenced in function "public:
char const * __thiscall _bstr_t::Data_t::GetString(void)const "
(?GetString@Data_t@_bstr_t@@QBEPBDXZ) UnityDecodeAsnUser.obj

Error 4 fatal error LNK1120: 3 unresolved
externals C:\Projects\UnityDecodeAsnUser\Debug\UnityDecodeAs nUser.dll

How can I correct this Lnk error?

--
Thanks.
"Bruno van Dooren [MVP VC++]" wrote:
One thing worth remembering is: you can use only declspec calling
convention....
Actually, declspec is not a calling convention. It's a declaration
specifier.
And you can use __stdcall, __fastcall or __cdecl calling convention.
Whatever is fit for your purpose.
Afaik there is no restriction on calling convention when using DllImport in
C#.

--

Kind regards,
Bruno van Dooren
br**********************@hotmail.com
Remove only "_nos_pam"

Aug 29 '06 #7

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

Similar topics

1
by: Ajith Nair | last post by:
Hi, I am new in Visual Basic .net. I did not find any option to create DLL or ActiveX module. Please help me to create. Thanks in Advance, Ajith
0
by: Me | last post by:
I am getting "A dynamic link library (DLL) initialization routine failed" error in IIS 6.0 on Windows 2003 server. I have this same code working on WiN-NT. Does anyone have an idea how to fix...
0
by: Marty | last post by:
Hi, I made a VB.NET class library DLL and I want to use it in my VC++.NET project. How do I insert it in my project? Thanks you Marty
0
by: Eric van Wijk | last post by:
Hi All, After installing SP1 for Windows 2003, I'm running into the 'Error loading type library/DLL' exception when using CDO through System.Web.Mail: ...
1
by: madushan | last post by:
hi all, once i try to generate .cs file by using the aximp.exe tool it gives the error the command I used: C:\Documents and Settings\malik\Desktop\tt>aximp SHDocVw.dll...
0
by: hendyhanusin | last post by:
Dear all, Pls help in JavaScript coding since i'm a beginner in JavaScript . i have a .NET class library (DLL) : ACR120DLL.ACR120DLL... Does anybody know how to use this DLL event (AddList,...
0
satyanagendra
by: satyanagendra | last post by:
hi, Can we create DLL using turboc in windows. I am able to create static libraries using turboc. But I don't know how to make DLL files using turboc If it is possible tell me how to make and...
4
by: minermadison | last post by:
Hello, I need to have a .dll start up and pass some information to an .exe, then receive some information back. The only way I can think of doing this currently is to use Process.Start and/or...
1
by: Abhijit D. Babar | last post by:
Hello, I have insatlled Visual Studio 2008. I have to create DLL in Project type Visual C++. Which Template i have to select to reate dll, MFC DLL or Class Library?. I have to call or import...
3
by: =?Utf-8?B?anBhdHJjaWs=?= | last post by:
Don't see any official notice that compiled library dll's loaded in the BIN directory of an asp.net website need to be thread safe, but concurrent visits to the same web site sure bear this out....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.