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

Best way for C# application to access VC application

Hi,
I have a C# .Net application which needs to use some feature which can
be only developed in Visual C++ (its extended MAPI).

The C# exe will be supplied to users without a setup.

What kind of exe/dll should I develop in Visual C++ so that I can meet
these requirements

1) No administrator rights are required
2) C# application can use the feature in the VC dll/exe if the dll is
present in the same folder and should run even if its not there.
3) If required the VC exe/dll can be embedded inside the C# exe as a
resource and when required the file can created by extracting the
resource by application itself.

As per my understanding, dynamic link library is the only solution. If
there is any other option please let me know.

Regards,
Ashutosh Bhawasinka
Jun 27 '08 #1
7 1600
You can PInvoke any exported functions in any binary, EXE or DLL.

If it's a native-only C++ binary then you can only PInvoke exported
functions. i.e. you can't get access to native classes from a managed
language.

If you want to access native classes from a managed language you can write
managed wrappers for them in C++ and produce a mixed-mode DLL. This allows
other managed applications to access the managed classes in this mixed-mode
DLL that in term access the native classes.

This shouldn't require administrative rights (other than for install, which
you've said isn't an issue) but the mixed-mode DLL will likely need unsafe
code rights in CAS.
--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#
"Ashutosh Bhawasinka" wrote:
Hi,
I have a C# .Net application which needs to use some feature which can
be only developed in Visual C++ (its extended MAPI).

The C# exe will be supplied to users without a setup.

What kind of exe/dll should I develop in Visual C++ so that I can meet
these requirements

1) No administrator rights are required
2) C# application can use the feature in the VC dll/exe if the dll is
present in the same folder and should run even if its not there.
3) If required the VC exe/dll can be embedded inside the C# exe as a
resource and when required the file can created by extracting the
resource by application itself.

As per my understanding, dynamic link library is the only solution. If
there is any other option please let me know.

Regards,
Ashutosh Bhawasinka
Jun 27 '08 #2
Thanks for your comments. I can't create a mixed mode dll as you said
because the user won't even have the admin rights for installation.

So, I have decided to create a native C++ dll.

Now I have two choices, either to use PInvoke or use reflection to
access the functions.

Which one do you suggest?? The application should run even if the DLL is
not present. As per my understanding reflection is OK for this, but I
haven't tried PInvoke with the case when the dll is not present.

Regards,
Ashutosh Bhawasinka

Peter Ritchie [C# MVP] wrote:
You can PInvoke any exported functions in any binary, EXE or DLL.

If it's a native-only C++ binary then you can only PInvoke exported
functions. i.e. you can't get access to native classes from a managed
language.

If you want to access native classes from a managed language you can write
managed wrappers for them in C++ and produce a mixed-mode DLL. This allows
other managed applications to access the managed classes in this mixed-mode
DLL that in term access the native classes.

This shouldn't require administrative rights (other than for install, which
you've said isn't an issue) but the mixed-mode DLL will likely need unsafe
code rights in CAS.
Jun 27 '08 #3
You can't use refelection on a native binary, so Pinvoke is the only option.
As ons as you don't try to execute the PInvoke methods when the DLL isn't
there, you should have no problems.

--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#
"Ashutosh Bhawasinka" wrote:
Thanks for your comments. I can't create a mixed mode dll as you said
because the user won't even have the admin rights for installation.

So, I have decided to create a native C++ dll.

Now I have two choices, either to use PInvoke or use reflection to
access the functions.

Which one do you suggest?? The application should run even if the DLL is
not present. As per my understanding reflection is OK for this, but I
haven't tried PInvoke with the case when the dll is not present.

Regards,
Ashutosh Bhawasinka

Peter Ritchie [C# MVP] wrote:
You can PInvoke any exported functions in any binary, EXE or DLL.

If it's a native-only C++ binary then you can only PInvoke exported
functions. i.e. you can't get access to native classes from a managed
language.

If you want to access native classes from a managed language you can write
managed wrappers for them in C++ and produce a mixed-mode DLL. This allows
other managed applications to access the managed classes in this mixed-mode
DLL that in term access the native classes.

This shouldn't require administrative rights (other than for install, which
you've said isn't an issue) but the mixed-mode DLL will likely need unsafe
code rights in CAS.
Jun 27 '08 #4
Hi Ashutosh,

I agree with Peter that for accessing native c/c++ dll, you cannot use .NET
reflection which is used for managed assembly only. So far calling native
dll via PInvoke is the reasonable approach for this scenario.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>Date: Thu, 01 May 2008 00:12:45 +0530
MIME-Version: 1.0
Subject: Re: Best way for C# application to access VC application
>Thanks for your comments. I can't create a mixed mode dll as you said
because the user won't even have the admin rights for installation.

So, I have decided to create a native C++ dll.

Now I have two choices, either to use PInvoke or use reflection to
access the functions.

Which one do you suggest?? The application should run even if the DLL is
not present. As per my understanding reflection is OK for this, but I
haven't tried PInvoke with the case when the dll is not present.

Regards,
Ashutosh Bhawasinka

Peter Ritchie [C# MVP] wrote:
>You can PInvoke any exported functions in any binary, EXE or DLL.

If it's a native-only C++ binary then you can only PInvoke exported
functions. i.e. you can't get access to native classes from a managed
language.

If you want to access native classes from a managed language you can
write
>managed wrappers for them in C++ and produce a mixed-mode DLL. This
allows
>other managed applications to access the managed classes in this
mixed-mode
>DLL that in term access the native classes.

This shouldn't require administrative rights (other than for install,
which
>you've said isn't an issue) but the mixed-mode DLL will likely need
unsafe
>code rights in CAS.
Jun 27 '08 #5
Hi Ashutosh,

Have you got progress on this issue? Did you use the PINVOKE approach for
calling the NATIVE code? If there is any further questions, welcome to post
here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>From: st*****@online.microsoft.com (Steven Cheng [MSFT])
Organization: Microsoft
Date: Thu, 01 May 2008 04:10:51 GMT
Subject: Re: Best way for C# application to access VC application
>Hi Ashutosh,

I agree with Peter that for accessing native c/c++ dll, you cannot use
..NET
>reflection which is used for managed assembly only. So far calling native
dll via PInvoke is the reasonable approach for this scenario.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

================================================= =
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ault.aspx#noti
f
>ications.

================================================= =
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>>Date: Thu, 01 May 2008 00:12:45 +0530
MIME-Version: 1.0
Subject: Re: Best way for C# application to access VC application
>>Thanks for your comments. I can't create a mixed mode dll as you said
because the user won't even have the admin rights for installation.

So, I have decided to create a native C++ dll.

Now I have two choices, either to use PInvoke or use reflection to
access the functions.

Which one do you suggest?? The application should run even if the DLL is
not present. As per my understanding reflection is OK for this, but I
haven't tried PInvoke with the case when the dll is not present.

Regards,
Ashutosh Bhawasinka

Peter Ritchie [C# MVP] wrote:
>>You can PInvoke any exported functions in any binary, EXE or DLL.

If it's a native-only C++ binary then you can only PInvoke exported
functions. i.e. you can't get access to native classes from a managed
language.

If you want to access native classes from a managed language you can
write
>>managed wrappers for them in C++ and produce a mixed-mode DLL. This
allows
>>other managed applications to access the managed classes in this
mixed-mode
>>DLL that in term access the native classes.

This shouldn't require administrative rights (other than for install,
which
>>you've said isn't an issue) but the mixed-mode DLL will likely need
unsafe
>>code rights in CAS.

Jun 27 '08 #6
Hi Steve,

Need your help again. I am having a problem.

I have a C++ DLL, it exports some some plain C style functions. This
functions internally initializes COM and then MAPI. This works fine if I
use the DLL from a C++ application (I tested with a C++ Win32 console
application).

But, when I call/invoke those functions from a C# .Net application using
PInvoke, COM initialization is fails in the DLL.

Do I need to initialize something??

Regards,
Ashutosh

Steven Cheng [MSFT] wrote:
Hi Ashutosh,

Have you got progress on this issue? Did you use the PINVOKE approach for
calling the NATIVE code? If there is any further questions, welcome to post
here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>From: st*****@online.microsoft.com (Steven Cheng [MSFT])
Organization: Microsoft
Date: Thu, 01 May 2008 04:10:51 GMT
Subject: Re: Best way for C# application to access VC application
>Hi Ashutosh,

I agree with Peter that for accessing native c/c++ dll, you cannot use
.NET
>reflection which is used for managed assembly only. So far calling native
dll via PInvoke is the reasonable approach for this scenario.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

================================================= =
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ault.aspx#noti
f
>ications.

================================================= =
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>>Date: Thu, 01 May 2008 00:12:45 +0530
MIME-Version: 1.0
Subject: Re: Best way for C# application to access VC application
Thanks for your comments. I can't create a mixed mode dll as you said
because the user won't even have the admin rights for installation.

So, I have decided to create a native C++ dll.

Now I have two choices, either to use PInvoke or use reflection to
access the functions.

Which one do you suggest?? The application should run even if the DLL is
not present. As per my understanding reflection is OK for this, but I
haven't tried PInvoke with the case when the dll is not present.

Regards,
Ashutosh Bhawasinka

Peter Ritchie [C# MVP] wrote:
You can PInvoke any exported functions in any binary, EXE or DLL.

If it's a native-only C++ binary then you can only PInvoke exported
functions. i.e. you can't get access to native classes from a managed
language.

If you want to access native classes from a managed language you can
write
>>>managed wrappers for them in C++ and produce a mixed-mode DLL. This
allows
>>>other managed applications to access the managed classes in this
mixed-mode
>>>DLL that in term access the native classes.

This shouldn't require administrative rights (other than for install,
which
>>>you've said isn't an issue) but the mixed-mode DLL will likely need
unsafe
>>>code rights in CAS.
Jun 27 '08 #7
Hi Ashutosh,

Thanks for your followup. I've also seen your new posts regarding on the
COM interop issue. Some other engineers have been working with you there.
Welcome to continue discuss in those threads.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
--------------------
>Date: Sat, 17 May 2008 22:05:17 +0530
From: Ashutosh Bhawasinka <sm*******@nospam.nospam>
User-Agent: Thunderbird 2.0.0.14 (Windows/20080421)
MIME-Version: 1.0
Subject: Re: Best way for C# application to access VC application
rp
>
Hi Steve,

Need your help again. I am having a problem.

I have a C++ DLL, it exports some some plain C style functions. This
functions internally initializes COM and then MAPI. This works fine if I
use the DLL from a C++ application (I tested with a C++ Win32 console
application).

But, when I call/invoke those functions from a C# .Net application using
PInvoke, COM initialization is fails in the DLL.

Do I need to initialize something??

Regards,
Ashutosh

Steven Cheng [MSFT] wrote:
>Hi Ashutosh,

Have you got progress on this issue? Did you use the PINVOKE approach
for
>calling the NATIVE code? If there is any further questions, welcome to
post
>here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

Jun 27 '08 #8

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

Similar topics

13
by: Atlas | last post by:
I've developed years ago a small business application (about ten tables, basic relationships, 10 forms, 3 reports a few queries) with Borland Paradox 7, most of it developed with wizards and little...
2
by: Tim | last post by:
I am doing a small asp webshop and want to make it atleast bi-lingual. I have thought of a few ways to do this but would like to have a second opinion on what you think is the best way. I have...
11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
4
by: Paul Merrion | last post by:
I recently became registrar for a girls' softball league and will be inheriting the previous registrar's Access database of team and player information. I have Office XP for Students and Teachers,...
17
by: | last post by:
I have an app that retrieves data from an Access database. At the moment I have the SQL string as a Const in my app. I understand this is not best practice. I don't want the user to have access to...
20
by: Keith G. Murphy | last post by:
I'm trying to get a feel for what most people are doing or consider best practice. Given a mod_perl application talking to a PostgreSQL database on the same host, where different users are...
9
by: JAKDND | last post by:
I'm trying to find out the best architecture would be for a web+access solution. We have a database of individuals' job details. There's a big table with an ID key field, name addess etc, and a...
13
by: BK | last post by:
Our .Net team has just inherited a junior programmer that we need to get up to speed as quickly as possible. Unfortunately, his skill set is largely Access with some VB6 and ASP classic...
6
by: kamsmartx | last post by:
I'm new to programming and need some help figuring out an algorithm. I need to design some kind of algorithm which will help us define capacity for one of our portfolios....here's the problem...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.