473,586 Members | 2,639 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

call c# dll function from another app

What I'm trying to do is invoke a c# dll from a c++ application. I
don't know whether my problem is in the c# or the c++ code.

My c# dll contains a public static function that I'm trying to invoke.
However, I can't obtain a pointer to the function. Using
AfxLoadLibrary from the c++ side, the library loads fine, but
GetProcAddress returns null.

I've been searching through documentation, but came up empty. What am
I missing?

Feb 2 '06 #1
4 1714
dotnetchic,

.NET dlls can not be accessed in this manner, since they do not export
functions that can be found using GetProcAddress.

Rather, you have to expose your object as a COM object in order to use
it in unmanaged code, or use managed C++ to access it (the latter being the
easier, in my opinion).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"dotnetchic " <do********@gma il.com> wrote in message
news:11******** *************@g 44g2000cwa.goog legroups.com...
What I'm trying to do is invoke a c# dll from a c++ application. I
don't know whether my problem is in the c# or the c++ code.

My c# dll contains a public static function that I'm trying to invoke.
However, I can't obtain a pointer to the function. Using
AfxLoadLibrary from the c++ side, the library loads fine, but
GetProcAddress returns null.

I've been searching through documentation, but came up empty. What am
I missing?

Feb 2 '06 #2

"dotnetchic " <do********@gma il.com> wrote in message
news:11******** *************@g 44g2000cwa.goog legroups.com...
| What I'm trying to do is invoke a c# dll from a c++ application. I
| don't know whether my problem is in the c# or the c++ code.
|
| My c# dll contains a public static function that I'm trying to invoke.
| However, I can't obtain a pointer to the function. Using
| AfxLoadLibrary from the c++ side, the library loads fine, but
| GetProcAddress returns null.
|
| I've been searching through documentation, but came up empty. What am
| I missing?
|

C# (or managed assemblies) cannot be loaded by LoadLibrary and family, what
you can do is build a wrapper library in C++ (mixed mode) that wraps the C#
classes and thunks the calls from C++. Yet another option is to use COM
interop to create and access your C# classes.
Check this: http://msdn2.microsoft.com/en-us/library/ms177552.aspx for "C++
interop", I would also suggest you to post your questions to a vc NG or one
the vc forums at http://forums.microsoft.com.
Willy.

Feb 2 '06 #3
Here is an example which uses COM Interop to expose a .NET assembly to
COM clients. This particular example exposes the DLL to a Java client,
but the COM Interop steps for generating the COM callable wrapper are
the same for any COM client.

http://j-integra.intrinsyc.com/suppo...?article=78813

Regards,
Shane Sauer
------------------------------------------------------------------------------
J-Integra Interoperabilit y Solutions
http://j-integra.intrinsyc.com/
high performance interop middleware for java, corba, com & .net

Feb 2 '06 #4
Thanks. I may try that route. I was hoping to opt for the easy way
out, though...

Feb 3 '06 #5

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

Similar topics

4
3381
by: mangi03 | last post by:
Hi, I came acrosss g++ compile errors whenever I make a function call by reference and found out from the test program that compiler is treating the function argument differently when another function call funcRet()is made which returns the expected argument type for the function call by reference funcByRef(class A&); The only way to get...
3
4026
by: JoeK | last post by:
Hey all, I am automating a web page from Visual Foxpro. I can control all the textboxes, radio buttons, and command buttons using syntax such as: oIE.Document.Forms("searchform").Item(<name>).Value = <myvalue> But I cannot control a dropdown with an onchange event. I can set the dropdown's value and selectedIndex, but then calling the...
39
6507
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. When it completes, it can call a success, or a failure function. The names of these success, or failure functions will differ, and I'd like to know...
2
2993
by: FAN | last post by:
I want to define some function in python script dynamicly and call them later, but I get some problem. I have tried the following: ################################## # code ################################## class test: def __init__(self): exec("def dfunc(msg):\n\tprint msg\nprint 'exec def function'") dfunc('Msg in init ...') # it...
13
4115
by: Bern McCarty | last post by:
I have run an experiment to try to learn some things about floating point performance in managed C++. I am using Visual Studio 2003. I was hoping to get a feel for whether or not it would make sense to punch out from managed code to native code (I was using IJW) in order to do some amount of floating point work and, if so, what that certain...
5
6525
by: Kurt Van Campenhout | last post by:
Hi, I am trying to get/set Terminal server information in the active directory on a windows 2000 domain. Since the ADSI calls for TS don't work until W2K3, I need to do it myself. I'm fairly new to VB.NET, so I need some help. Here is a code snippit :
5
2307
by: SStory | last post by:
Hi all, I really needed to get the icons associated with each file that I want to show in a listview. I used the follow modified code sniplets found on the internet. I have left in commented code for anyone else who may be looking to do the same.
6
4260
by: mygoogleaccount | last post by:
Hi, may be someone could help me ? i need to use cyrillic letters in a php application. I changed everything to UTF-8 and it works fine. The only problem are CYRILLIC SMALL LETTER ES CYRILLIC SMALL LETTER YA
46
3804
by: Steven T. Hatton | last post by:
I just read §2.11.3 of D&E, and I have to say, I'm quite puzzled by what it says. http://java.sun.com/docs/books/tutorial/essential/concurrency/syncrgb.html <shrug> -- NOUN:1. Money or property bequeathed to another by will. 2. Something handed down from an ancestor or a predecessor or from the past: a legacy of religious freedom....
11
2726
by: Felix Kater | last post by:
Hi, I can compile and run this code (see below) which twice calls the function f, first with too less, second with too much arguments. But is it legal and free of memory leaks and other problems? Of course, I presume that inside f I don't access i in case it was called via g. int f(int i){ /* ... */ return 0; }
0
7839
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8202
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. ...
0
8338
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...
1
7959
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...
0
8216
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5390
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...
0
3837
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...
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1180
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...

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.