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

C++ ClassLib for C#

I'd like to port some C++ code to a .NET ClassLib for C# consumers.

Am using VC2005, .NET 2.0

However I find that If I simply generate a C++ ClassLib using the wizard...

// SimpleCLib.h
#pragma once
using namespace System;
namespace SimpleCLib {
public ref class Class1
{
// TODO: Add your methods for this class here.
};

}

Then generate a C# console app, add the Lib Reference and a new instance of Class1 it generates a runtime error. The error is 'System.BadImageFormatException'

using System;
using System.Collections.Generic;
using System.Text;

namespace CSharpConsoleTest {
class Program
{
static void Main(string[] args)
{
SimpleCLib.Class1 scl = new SimpleCLib.Class1;
}
}
}

After some investigation, I am not seeing anything other than verifying /FIXED:no setting in the linker.

Any help would be appreciate, thanks - Mike

Jun 30 '06 #1
4 2000
mike wrote:
Then generate a C# console app, add the Lib Reference and a new instance
of Class1 it generates a runtime error. The error is
'System.BadImageFormatException'

using System;
using System.Collections.Generic;
using System.Text;

namespace CSharpConsoleTest {

class Program
{
static void Main(string[] args)
{
SimpleCLib.Class1 scl = new SimpleCLib.Class1;
}
}
}


I setup two projects as you described, and added a reference to the C#
project pointing to the DLL output of the C++ project. The only change
I made to your code was to add parens after the class name:

SimpleCLib.Class1 x = new SimpleCLib.Class1();

Everything compiled fine. I also tested by adding a project reference
with both projects in the same solution, and that worked fine.

How are you adding the reference in your C# project to the C++ output?
Could you possibly copy/paste the output of the build?

-Matthew
Jun 30 '06 #2
Thanks for the aid Mathew,

I do forget those parens often.

But this is good news.

Yes, the Reference added to the C# project is for the .dll in the C++ project's output dir.

So it did execute alright? I will have to dig into another workstation a give a try.

I have been testing all week with a C++ CLR console app and now that I have switched to the C# console I hit this runtime exception.
Jul 1 '06 #3
mike wrote:
Thanks for the aid Mathew,

I do forget those parens often.

But this is good news.

Yes, the Reference added to the C# project is for the .dll in the C++
project's output dir.

So it did execute alright? I will have to dig into another workstation a
give a try.

I have been testing all week with a C++ CLR console app and now that I
have switched to the C# console I hit this runtime exception.


It executed just fine when I ran it.

Another thing to check is to make sure both the C# app and the C++
library are built for the same version of the .NET runtime.
Jul 1 '06 #4
Yep, works great at other machines.

You got me in the right direction.

Turns out I have to compile the C++ ClassLib to "x64" for it to work on my
x64 machine.

Thanks,

- Mike
Jul 5 '06 #5

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

Similar topics

15
by: anders | last post by:
Hi! I have a config file that looks like this: <?xml version="1.0" encoding="utf-8" ?> <configuration> <system.runtime.remoting> <application> <service> <wellknown mode="SingleCall"...
1
by: Matthias Pieroth | last post by:
Hi NG, I have an OCX (VC++ 6.0) that fires some events. I have to use it on a form an have to catch the events in event-handlers in another form (MDI-Child). BUT: I have to create the other...
2
by: Demetri | last post by:
I have a class library, lets call it ClassLib, which contains an abstract class, lets call it Entity, that acts as sort of a marker. I have a web service that consumes the ClassLib to make use...
2
by: dan | last post by:
I have created a class called BasePage that inherits from System.Web.UI.Page so that I can implement a "template" for all pages in an app. My BasePage class is in a class library project and there...
4
by: M. Posseth | last post by:
Does someone knows a easy way how to acomplsih the folowing i made a online catalogue with order basket the orders that i store in my database should be submitted to a other webserver...
6
by: cpnet | last post by:
I've authored a custom web component (a non-ui component kinda like a DataSet) and so far it's working. When my web component is added to the web form in the designer from the toolbox, the...
1
by: Dino M. Buljubasic | last post by:
How can I get date stamp of a file stored on an FTP server from a VB.net application? Thank you, -- Dino Buljubasic Software Developer http://rivusglobal.com
3
by: Marty | last post by:
Hi, I want to upload one file to a ftp server. I read this article, but it don't tell me how to coordinate the upload command on one port and to send the file on the second port....
6
by: Joseph Geretz | last post by:
I'd like to break up my aplication into a WinForm executable, plus a class library containing application utility functions. But I don't want any client other than my own application to have access...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.