473,395 Members | 2,443 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,395 software developers and data experts.

Exporting ative type compiled with /CLR

How do I export native types compiled with option /CLR (MSIL code)? I
am able to export MSIL code with __declspec(dllexport) as long as no
CLR data is involved, but I get the following compiler error if I try
to pass CLR data to a MSIL function.

"__declspec(dllexport) cannot be applied to a function with the
__clrcall calling convention"

I have noticed that a MSIL function exported with __declspec(dllexport)
involves a managed transition even when it is called from another MSIL
module. I think, I do understand why this is necessary, but there must
be a better way to "export" native types between MSIL modules. I have
tried with #using DLL, but apparently, it does not work for native
types. Below is a code example, which illustrates what I am trying to
do.

--------------------------
Library code (library.dll)
--------------------------
Header file
-----------
class base {
public:
virtual ~base() {}
virtual void write(unsigned char);
};

class derived : public base {
private:
gcroot<System::IO::Stream^out_;
void write(unsigned char);
public:
derived(System::IO::Stream^ out);
};

-----------
Source file
-----------
derived::derived(System::IO::Stream^ out) : out_(out) {}

void derived::write(unsigned char ch)
{
out_->WriteByte(ch);
}

--------------------------
Program code (program.exe)
--------------------------
#include "library.h"

#using <library.dll// desperate attempt

int main()
{
base* p = new derived(gcnew System::IO::FileStream("a.bin",
System::IO::FileMode::Create));
p->write('a');
delete p;
}
Thanks in advance
Jesper

Nov 1 '06 #1
0 741

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

Similar topics

1
by: Jacky11 | last post by:
I have a column name the Data type is MEMO The input is more than thousands of characters. When exporting, not all the information is exported. Who can I correct this problem? Thanks
2
by: Kenneth | last post by:
How do I remove the limitation in Access that deny me from exporting 24000 rows and 17 columns (in a query) into Excel? Kenneth
3
by: nikola | last post by:
is it possible to export (and, above all, import afterwards) an unmanaged class from a managed dll (compiled with the /clr switch. it would in fact probably result in a mixed mode dll)? it seems that...
7
by: Gustavo L. Fabro | last post by:
Greetings! Some classes that once compiled without problems on VS 2003 have now problems on VS 2005 Beta 1. I'm talking about a __nogc class that is exported with __declspec(dllexport). The...
7
by: victorsk | last post by:
Hello, I have a dll which I compiled in VB. Now I would like to use this dll in MapBasic program. However, I keep getting an error saying that the function which I am calling cannong be found....
3
by: David P. Donahue | last post by:
I'm re-writing an application in C# that was originally written in Delphi 7. The heart of the application is a DataSet displayed in a DataGrid. One of the main functions of the previous...
3
by: 2b|!2b==? | last post by:
I have a C++ library partitioned by namespaces. I want to export some of the functions in one of the namespace - how do I do it. Assuming I have the macro MYAPI_EXPORTS #defined to be a declspec...
6
by: A n g l e r | last post by:
Hello there. I've got a DLL written in C convention. There're a few of enum types that I would like to make available to C#. Is there any easy way of doing this (exporting, etc.), or do I have...
4
by: myemail.an | last post by:
Hi all, I use Access 2007 and have the following problems: when exporting banal select queries (either to Excel or to a csv file) I find that exporting often doesn't work and creates a file with...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.