473,395 Members | 1,972 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,395 software developers and data experts.

Calling C# Methods in a Dll file from a unmanaged C++ Program

Im writting a program in unmanaged C++, and want to access a MS SQL
Database. I've done quite a lot of database access stuff in C# before so I'm
wanting to use C# for the database access in the program.

I want to write a C# DLL file where I can call methods from the C++ program
so that it can get data out of the database. The C++ program is only needing
to get a few things from the database so it's going to be simpler to just
use C# for this, and im not trying to create a wrapper for a lot of .NET
database functions or anything like that.

So how do I go about writting a C# Dll and accessing it from unmanaged C++?

Thank You for any help,
Grant
Nov 15 '05 #1
4 1646
Use tlbexp to generate a Com based wrapper for your .Net code. With the
wrapper, you can simply call your .Net code as though it was a COM object.

"Grant Stanley" <ag**@kent.ac.uk.delete> wrote in message
news:40*********************@lovejoy.zen.co.uk...
Im writting a program in unmanaged C++, and want to access a MS SQL
Database. I've done quite a lot of database access stuff in C# before so I'm wanting to use C# for the database access in the program.

I want to write a C# DLL file where I can call methods from the C++ program so that it can get data out of the database. The C++ program is only needing to get a few things from the database so it's going to be simpler to just
use C# for this, and im not trying to create a wrapper for a lot of .NET
database functions or anything like that.

So how do I go about writting a C# Dll and accessing it from unmanaged C++?
Thank You for any help,
Grant

Nov 15 '05 #2
Kevin is absolutly correct that you need a COM callable wrapper to use .NET
code from the unmanged world...

I am just wondering why you canīt use C++ to access the database in the
first place? Somehow it seems kind of wrong to access the db through .NET if
you still are going to need C++ for the most part and only needs a few parts
from a db??

Anyway good luck!
/Oscar
"Grant Stanley" <ag**@kent.ac.uk.delete> wrote in message
news:40*********************@lovejoy.zen.co.uk...
Im writting a program in unmanaged C++, and want to access a MS SQL
Database. I've done quite a lot of database access stuff in C# before so I'm wanting to use C# for the database access in the program.

I want to write a C# DLL file where I can call methods from the C++ program so that it can get data out of the database. The C++ program is only needing to get a few things from the database so it's going to be simpler to just
use C# for this, and im not trying to create a wrapper for a lot of .NET
database functions or anything like that.

So how do I go about writting a C# Dll and accessing it from unmanaged C++?
Thank You for any help,
Grant

Nov 15 '05 #3
IL has attributes for exporting managed methods as C style method exports. If
you were
savvy, and didn't want to write a CCW you could probably work at the IL level to
export
your methods.
--
Justin Rogers
DigiTec Web Consultants, LLC.

"Oscar Thornell" <os***@cyberode.se> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Kevin is absolutly correct that you need a COM callable wrapper to use .NET
code from the unmanged world...

I am just wondering why you canīt use C++ to access the database in the
first place? Somehow it seems kind of wrong to access the db through .NET if
you still are going to need C++ for the most part and only needs a few parts
from a db??

Anyway good luck!
/Oscar
"Grant Stanley" <ag**@kent.ac.uk.delete> wrote in message
news:40*********************@lovejoy.zen.co.uk...
Im writting a program in unmanaged C++, and want to access a MS SQL
Database. I've done quite a lot of database access stuff in C# before so

I'm
wanting to use C# for the database access in the program.

I want to write a C# DLL file where I can call methods from the C++

program
so that it can get data out of the database. The C++ program is only

needing
to get a few things from the database so it's going to be simpler to just
use C# for this, and im not trying to create a wrapper for a lot of .NET
database functions or anything like that.

So how do I go about writting a C# Dll and accessing it from unmanaged

C++?

Thank You for any help,
Grant


Nov 15 '05 #4
The reason is that I know how to access the SQL database from .NET but I
have no idea how to do it easily in C++

If its as easy as from C# then I will certainly try. I guess I should look
into it.

Grant

"Oscar Thornell" <os***@cyberode.se> wrote in message
news:#V**************@TK2MSFTNGP10.phx.gbl...
Kevin is absolutly correct that you need a COM callable wrapper to use ..NET code from the unmanged world...

I am just wondering why you canīt use C++ to access the database in the
first place? Somehow it seems kind of wrong to access the db through .NET if you still are going to need C++ for the most part and only needs a few parts from a db??

Anyway good luck!
/Oscar
"Grant Stanley" <ag**@kent.ac.uk.delete> wrote in message
news:40*********************@lovejoy.zen.co.uk...
Im writting a program in unmanaged C++, and want to access a MS SQL
Database. I've done quite a lot of database access stuff in C# before so

I'm
wanting to use C# for the database access in the program.

I want to write a C# DLL file where I can call methods from the C++

program
so that it can get data out of the database. The C++ program is only

needing
to get a few things from the database so it's going to be simpler to just use C# for this, and im not trying to create a wrapper for a lot of .NET
database functions or anything like that.

So how do I go about writting a C# Dll and accessing it from unmanaged

C++?

Thank You for any help,
Grant


Nov 15 '05 #5

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

Similar topics

4
by: jarmopy | last post by:
Hi, I have made a service with C# and calling that service class from another C# program with remoting. (Referendes from the calling program) That service class is configured so that garpage...
1
by: seash | last post by:
class xyz{ public void somefunction{ if(this.folderBrowserDialog1.ShowDialog() == DialogResult.OK) { m_varFolderPath = this.folderBrowserDialog1.SelectedPath; m_varFolderPath += ...
0
by: Mike Collins | last post by:
I apologize for using this newsgroup for what seems like a VB6 question, but I did not see a newsgroup for VB6. I also think I may not have the C# code setup correctly for calling from VB6. If...
5
by: Virajitha Sarma | last post by:
Hi, Can u plz help me out with how to call a C# DLL from C... I tried to find out by searching in net..but i couldnot find anything on it.... Thanku Virajitha *** Sent via Developersdex...
1
by: Jesse McGrew | last post by:
Hi all, I'm trying to make a plugin DLL for a third-party application, using VC++ .NET 2003. This DLL acts as a bridge between the C++ plugin API of the application, and my actual plugin code...
9
by: Amit Dedhia | last post by:
Hi All I have a VC++ 2005 MFC application with all classes defined as unmanaged classes. I want to write my application data in xml format. Since ADO.NET has buit in functions available for...
3
by: Klaus | last post by:
Hi, I have an existing VC 6 MFC application which communicates asynchronly with a VC 2005 managed code dll. I use an unmanaged base class with virtual functions to access methods in the MFC...
7
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a C# logging assembly with a static constructor and methods that is called from another C# Assembly that is used as a COM interface for a VB6 Application. Ideally I need to build a file...
4
by: MichK | last post by:
Hello all, I'm having some problems passing strings to a native (unmanaged) c++ dll I've written. There are lots of examples I can find on the internet considering passing strings to char*, yet I...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
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
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...
0
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...
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...

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.