473,688 Members | 3,241 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem with calling C++/CLI wrapper to C++ code from C# applicati

I need to write a C# application that uses unmanaged C++ code. I created a
C++/CLI wrapper to C++ code and encountered the following problem. Any time I
try to instantiate a wrapper in C# application the program crashes with an
error
"An unhandled exception of type 'System.IO.File NotFoundExcepti on' occurred
in mscorlib.dll, Additional information: The specified module could not be
found. (Exception from HRESULT: 0x8007007E)". C# application has a reference
only to the wrapper and the wrapper has a reference to unmanaged dll. Similar
application written in C++/CLI gives exactly the same error if it has a
reference only to the wrapper namespace. In case of C++/CLI application,
VS2005 allows to add a reference to unmanaged dll and then the application
works OK.
I have seen an example of managed C++ wrapper that is virtual identical to
the code below and is claimed to work with C#
(http://www.ondotnet.com/lpt/a/4731)
Cannot figure out what is the problem with my code.
Here is the code

//CppLib.h
#ifndef _CPPLIB_EXPORT_ IMPORT
#ifdef _CPPLIB_EXPORT
#define _CPPLIB_EXPORT_ IMPORT __declspec(dlle xport)
#else
#define _CPPLIB_EXPORT_ IMPORT __declspec(dlli mport)
#endif
#endif

class _CPPLIB_EXPORT_ IMPORT CCppLib
{
double _a;
double _b;
double _c;

public:
CCppLib(double a, double b, double c);
~CCppLib(){};

bool IsValid();

};
//CppLib.cpp

CCppLib::CCppLi b(double a, double b, double c)
{
_a = a;
_b = b;
_c = c;
}

bool CCppLib::IsVali d()
{
return (_a + _b _c && _a + _c _b && _b + _c _a );
}

//CLRWrapper.h

#pragma once
#include "..\\CppLib\\Cp pLib.h"

using namespace System;

namespace CLRWrapper
{

public ref class Triangle
{
CCppLib* _CppLib;

public:

Triangle()
{
_CppLib = new CCppLib();
}

Triangle(double a, double b, double c)
{
_CppLib = new CCppLib(a, b, c);
}

~Triangle()
{
this->!Triangle();
}

!Triangle()
{
if (_CppLib != NULL)
delete _CppLib;
_CppLib = 0;
}

CCppLib* GetCppLib() { return _CppLib;}

bool IsValid()
{
if (_CppLib != NULL)
return _CppLib->IsValid();
return false;
}

};
}

// CLRTest.cpp C++/CLI test application
using namespace System;
using namespace CLRWrapper;

int main(array<Syst em::String ^^args)
{
Triangle^ tr = gcnew Triangle(1, 2, 3);
Console::WriteL ine(tr->IsValid());

return 0;
}

//Program.cs C# test application

using System;
using System.Collecti ons.Generic;
using System.Text;
using CLRWrapper;

namespace TestTriangle
{
class Program
{
static void Main(string[] args)
{
Triangle tr = new Triangle(0.1, 0.2, 0.3);
Console.WriteLi ne(tr.IsValid() );
}
}
}

--
phys
Dec 29 '06 #1
2 7251
"An unhandled exception of type 'System.IO.File NotFoundExcepti on' occurred
in mscorlib.dll, Additional information: The specified module could not be
found. (Exception from HRESULT: 0x8007007E)".
This error could have something to do with the manifest in debugging mode.
Try to generate and embed the manifest in the assembly (linker/manifest
propertypage)

I found this out by using the procmon utility to see what file the loader
was looking for (msvcr80d.dll).
Dec 29 '06 #2
It occured to be my error unrelated to anything written in the post.
If directories are properly assigned everything works fine.
--
phys
Jan 5 '07 #3

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

Similar topics

2
4453
by: Marc Shapiro | last post by:
I am relatively new to python (I have used it on and off for a few small projects over the last few years) so I imagine that what I am trying to do has already been done, but practical experience, even if it is reinventing the wheel, is still useful, so... I am trying to write a module to handle drop down menus using curses (on linux). Curses seems to have a wrapper for the panels library, but not forms, or menus. I am not even sure...
15
3346
by: Alfonso Morra | last post by:
Hi, I have some code from an example, that I want to retrofit into my project. The code from the example has the following line: SharedAppenderPtr myAppender( new RollingFileAppender("MyAppender")) I want to move this line of code to a constructor in a wrapper class, so that I can determine the appropriate Appender name during the object's
10
2131
by: Saso Zagoranski | last post by:
hi, this is not actually a C# problem but since this is the only newsgroup I follow I decided to post my question here (please tell me where to post this next time if you think this post shouldn't be here). I have two design questions: 1. what is the correct (or best) way to include database queries into the code if you plan on
1
7156
by: Adam Clauss | last post by:
I have an unmanaged C++ library that I need to use through C#. I created a Managed C++ class library and through it wrote a wrapper class to call what I need. However, one of the methods (an Initialize function in the unmanaged library) crashes everytime I call it. Initialize calls another function 'GetInstance' (a static member function of a class) which looks something like: CLibConfig& CLibConfig::GetInstance()
1
1454
by: Bill Soudan | last post by:
Hi all, I'm a MS/.NET newbie, diving right into CLR interop. I've worked through the various issues foreign to me as a UNIX guy: multiple heap issues because I was linking to different CRT instances (ugh), calling conventions, marshalling, etc. I'm stumped on one issue, though. Quick structural overview: straight C dll wrapped by C# wrapper class. C# wrapper provides the implementation for a number of function callbacks via...
4
3889
by: Jayme Pechan | last post by:
I have a ATL COM object that is loaded through Interop in a C# application. The COM object fires an event and one of the parameters is another object created inside the object. This object has a property on it that is also another object. private void pIObj_EventProc(MObj.MainObj pObj) { MObj.Obj mainobj = pObj.Obj; // IF I DON'T DO THE NEXT LINE, THE APPLICATION HANGS AT SOME LATER TIME // THE UI DOESN'T EVEN UPDATE....
2
1197
by: Mike Smith | last post by:
We are having an issue where .NET assemblies are inconsistently being found/not found. On some runs, everything runs fine. On other runs, we get exceptions saying that one of our assemblies was not found. Also, if we were to do a Search using Windows Explorer, sometimes the assembly show up, and sometimes it doesn't. We inherited this code and the original developers said the only way they were able to fix the problem was to reinstall...
6
3699
by: superdevo | last post by:
Hey everyone, I seem to be having a problem with my CSS in IE 7. The problem does not show up in FireFox though. I've setup an online store that originally had a #wrapper "container" and #body CSS tags with widths of 1000 pixels. I know that their are many internet users that still have low resolutions such as 800 pixels. So I set out to change the width of the storefront to around 780 pixels. I've changed the width for the #wrapper...
3
1546
by: ropo | last post by:
I have a managed wrapper class that has a delegate to be called from unmanaged code: public ref class CmmMessageCallbackWrapper { private: delegate void InternalMessageDelegate( void*, CmmService::Message::CMessage* ); public: CmmMessageCallbackWrapper()
0
8590
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
8528
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8782
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8786
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6453
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Duprť who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5807
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4321
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4547
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2215
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.