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

Win32, .Net, & COM Interoperability

Dear All,
I am trying to write a C# DLL that would work with VBA (in VBA I can directly call C# dll) and relatively old Win32 application (ArcView3.x). For Win32 application I would like to use C++ Dll wrapper. It is possible to call Win32 Dlls from there. I created small test Dlls (see below). It works fine under Win 2000 but under XP Win32 application crashes without any messages while reaching CoCreateInstance(…) (see C++ code below).
Do I need to add something to C# dll code (some attributes like [ComVisible(true)])?

Below are steps I performed:

1) C# Dll code:

namespace Cs_CLR_DLL
{
public class Class1 : IClass1
public Class1() { }

public int OpenForm1()
{
// Form1 f1 = new Form1();
// f1.ShowDialog();

return 1;
}

public interface IClass1
{
int OpenForm1();
}
}

AssemblyInfo.cs:

[assembly: ComVisible(true)]
// [assembly: Guid("32fa638b-e5fd-4ab0-aa5f-f34d0cfc4913")]


Register for COM interop check box (in Properties) is checked


2) register C# dll with regasm:
regasm MyC#Dll.dll /t MyC#Dll.tlb



3) MFC VC++ Dll code:

#include "atlbase.h"
#import "Cs_CLR_DLL.tlb" no_namespace


extern "C" __declspec(dllexport)
int CallFromAV1(){
AFX_MANAGE_STATE(AfxGetStaticModuleState());

HRESULT resH;
resH = CoInitialize(NULL); //initialising COM
assert( SUCCEEDED(resH) );

CComPtr<IClass1> m_pClient;

resH = CoCreateInstance(_uuidof(Class1),NULL, CLSCTX_SERVER,
_uuidof(IClass1), (void**)&m_pClient);
assert( SUCCEEDED(resH) );

resH = m_pClient->OpenForm1();
assert( SUCCEEDED(resH) );

return resH;
}

Thank you very much in advance
Oleg
Jun 14 '07 #1
0 1220

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Eitan | last post by:
Hello, I am using Visual Studio.net 2003. I am trying to find how to create Win32 DLL & Win32 Static Library. When going through the wizard it does not show me the option for these two project...
3
by: Dean L. Howen | last post by:
Could anyone tell me how to program win32 in C#?
1
by: CharlesHenri | last post by:
Hello, i plan to use a managed dll containing WinForm classes in an unmanaged win32 exe. Starting from NOTHING, how do i have to proceed ? I have found the following tutorial on...
3
by: Demetri | last post by:
Hello, My company has charged me with creating a web service that will validate a user and return the user's roles via Active Directory. The requirement is that the web service must return...
0
by: Vijay | last post by:
Prep Courses for International Certifications, CSTE & CSQA & ISEB & ISTQB &Business Analyst & SOA Certifications in HYDERABAD. After receiving overwhelming response to our last 50+ batches, ...
0
by: jbenezech | last post by:
Hi all , I have a perl/java app running under Win32. The application consists of a perl service (Win32::Daemon) and of java classes. The perl service calls every xx hours java classes to perform...
0
by: newbie73 | last post by:
Going through the tutorial on http://swig.org, I created the example files (pasted below). After generating the _wrap file, I tried compiling (using mingw32) and received a lot of undefined...
1
by: =?Utf-8?B?U3dhcG5pbA==?= | last post by:
I have C++ application with some functionality C# application with some functionality. I want to use some functions from C++ application in C# application or vicversa, then how can i do using...
1
by: Rami | last post by:
I use Winforms and win32 dll with interoperability. I want to port to WMF. Can I use and how the dll from my WPF application? Regards Rami
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
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...

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.