|
No, but you can covert System::String or std::string to char * on the managed C++ side.
|
|
|
|
|
#include "stdafx.h"
#include <iostream>
#include <numeric>
#include <functional>
#include <vector>
#include <iterator>
using namespace std;
void mm(int**a,int **b,int **c){
__declspec(align(16)) int at[4][4],bl[4][4];
for(int j=0; j<4; ++j)
for(int i=0; i4; ++i){
at[j][i] = a[i][j]; //transpose 1st operand
bl[j][i] = b[j][i]; //local aligned non aliased
}
for (int j = 0; j < 4; ++j) //return matrix multiply4x4
for (int i=0; i < 4; ++i)
c[j][i] =inner_product(&at[i][0],&at[i][4],&bl[j][0],0.f);
}
my question: when compilling these codes it compiles well. but how can i initialise the two matrices so that i can view the output: assume a[4][4]={1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4} and b[4][4]={3,3,3,3,5,5,5,5,6,6,6,6,7,7,7,7}.please help.i am using MS VISUAL STUDIO 2008smart lubobya
|
|
|
|
|
Hello All,
I'm working on a managed wrapper for an unmanaged C++ library, and would like to use the objects generated by the managed wrapper as a data source within a Windows Forms Application.
For compatibility reasons, I'm using Visual Studio 2005.
The managed wrapper is using C++ interop to connect to the unmanaged library.
The problem I'm running into is that as soon as I add any code to the wrapper which actually interfaces to the unmanaged library, the managed wrapper's assembly disappears from the "Add New Data Source..." -> "Object" wizard.
I'm guessing here, but it appears that as soon as my wrapper's assembly contains any native code, it can no longer be used as a DataSource.
So, my question is, is it possible to implement a DataSource in a mixed-mode DLL?
Thanks in advance,
Ron Aldrich
|
|
|
|
|
Ron Aldrich wrote: the managed wrapper's assembly disappears from the "Add New Data Source..." -> "Object" wizard.
Is it coming when you add again?
I think it is not a good idea to use the mixed-mode assembly in data binding. Can't you wrap it inside another type and use that for binding? So that changes on the mixed-mode assembly won't affect the binding.Best wishes,
Navaneeth
|
|
|
|
|
Navaneeth wrote: Is it coming when you add again?
It appears that as long as there is any native code in the assembly, the entire assembly disappears from "Add New Data Source...", even though the native code is generated by C++ interop. If I then remove the native code, the assembly reappears in "Add New Data Source...".
Navaneeth wrote: I think it is not a good idea to use the mixed-mode assembly in data binding. Can't you wrap it inside another type and use that for binding? So that changes on the mixed-mode assembly won't affect the binding.
I'm beginning to think that it's not only not a good idea, it's actually impossible. I think that it can be made to work using p/invoke, but C++ interop makes it fairly easy to convert between the std::string* and std::vector* objects emitted by the native library, and the System::String^ and System::Collections::ArrayList^ objects used within managed code.
At this point, I'm looking at either
1) Redesign the native library's API to emit structures that are more easily marshaled using p/invoke, or
2) Add yet another layer of wrappings, just to allow the use of bindings.
From the standpoint of coding time, the second approach is probably simplest.
Thanks for your time,
Ron Aldrich
|
|
|
|
|
An interface in C++/CLI can have operators as static functions of the interface. If I code an implicit cast operator for an interface the compiler accepts it:
// VC9ClrConsoleApplication.cpp : main project file.
#include "stdafx.h"
using namespace System;
interface class AnInterface
{
static operator int (AnInterface ^ af) { return af -> IntReturn(); }
int IntReturn();
};
int main(array<System::String ^> ^args)
{
Console::WriteLine(L"Hello World");
Console::ReadKey();
return 0;
}
This compiles with no errors.
If I change my operator from an implicit cast to an explicit cast I get a C2071 illegal storage class error:
// VC9ClrConsoleApplication.cpp : main project file.
#include "stdafx.h"
using namespace System;
interface class AnInterface
{
static explicit operator int (AnInterface ^ af) { return af -> IntReturn(); }
int IntReturn();
};
int main(array<System::String ^> ^args)
{
Console::WriteLine(L"Hello World");
Console::ReadKey();
return 0;
}
".\VC9ClrConsoleApplication.cpp(10) : error C2071: 'AnInterface::operator int' : illegal storage class".
I can so no reason why an implicit cast operator is allowed for an interface and an explcit cast operator is not allowed for an interface.
For an implicit cast operator one would be able to say:
AnInterface ^ ai = CreationFunctionFromClassImplementingInterface();
int i = ai;
For an explicit cast operator, if it worked with interfaces, one would be able to say:
AnInterface ^ ai = CreationFunctionFromClassImplementingInterface();
int i = static_cast<int>(ai);
Is this a bug or is it, for some reason I can not fathom, just the way C++/CLI is supposed to work.Edward Diener
|
|
|
|
|
There's no mention in the standard about this behavior, so it could technically be regarded as a bug I suppose.
Why don't you replace your interfaces with abstract base classes? Or retain the interface and then add an abstract base class to the hierarchy. It's not ideal but that should solve all these operator overloading related weirdness you are experiencing.
|
|
|
|
|
I reported this as a bug at https://connect.microsoft.com/VisualStudio/feedback/details/539309/interface-operator-bug-with-explicit-conversion-function[^].
Using an abstract base class, as opposed to an interface, means that I can not derive my own eventual class from any other class, but I am sure you know that. Also I can not derive my interfaces from that abstract base class. All in all, wrenching a design in order to please Microsoft's inability to correctly implement operators in interfaces is not my idea of correct programming.
Microsoft needs to get this right, not only in operators in interfaces in C++/CLI but clearly they should add operators in interfaces in C# also. Else they are nearly as bad as Java, which doesn't believe in user-defined operators at all ( though Scala does to Java's detriment ).
But what's the point of telling Microsoft obvious things which their own developers are not intelligent enough to know.Edward Diener
|
|
|
|
|
How to use
BACKGROUNDWORKER in vc++ clr net 2.0 need example
I copy backgroundworker sample code in c# and try to conver to c++ clr it doesnt't in vc++ correct ly can anyone help ??
thanks
|
|
|
|
|
|
Hi All
How can i use .net dll in vc++?I make dll in .net and want to use in vc++?
Please help me
|
|
|
|
|
See this article[^]. txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
Thanks for reply
Sorry i havn't got any think related to vc++ here?
|
|
|
|
|
MsmVc wrote: Sorry i havn't got any think related to vc++ here?
Well you just follow the article and work out how to use COM from C++ rather than VB; it's not that difficult. Alternatively you convert your C++ code to Managed C++ and use your .NET library directly. Those are the choices I'm afraid.txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
Thanks once again.
I try to use Managed C++ and use your .NET library directly.First register dll and then /.tlb file.I use Common Language Runtime Support (/clr).
Now next step i stuck here.
CMyClass1^ c=gcnew CMyClass1();
Then i got error.
error C3699: '^' : cannot use this indirection on type 'CClass1' compiler replacing '^' with '*' to continue parsing
error C2726: 'gcnew' may only be used to create an object with managed type
Now what i do.Please help me
|
|
|
|
|
MsmVc wrote: I try to use Managed C++ and use your .NET library
I've never published any .NET libraries, are you sure this is not in response to some article? I don't have experience of managed C++ but the compiler message suggests:
CMyClass1 c = gcnew CMyClass1(); txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
My project is a C++/CLI project that references a C# assembly. Every time I make a change in the C# assembly and build it, I get a message from the compiler, "Cannot inspect myCsharpDll.dll. Assuming significant changes...". The compiler then proceeds to rebuild the entire C++/CLI project too -- which is just excruciating since the main project is about 300 source code files in size.
I did some digging around and found a suggestion that this is could be caused if the ".dll.meta" file is not being generated for the referenced assembly. However, I have verified that the .dll.meta file for my C# assembly IS being created.
Can anyone shed some light on what project settings I need to get this nonsense to stop?
|
|
|
|
|
Update: The .dll.meta file is *NOT* being generated. Before I said it was, but I took a closer look at the file timestamps. It looks like a .meta file was created when I created the library project and has not been updated since. If I open it in a simple text editor, the contents only appear to be a string "No meta available".
How can I get my builds to populate that .dll.meta file with the most recent changes???
|
|
|
|
|
FYI... It looks like I resolved it by cleaning the solution and rebuilding everything. Now all my .dll.meta data file have metadata in them and I can't reproduce the problem when I make additional updates to the class library. Looks like a Visual Studio glitch.
|
|
|
|
|
In C++/CLI if I add an operator to an interface class and implement that interface in a ref class, the operator is not recognized for the ref class. But if I add an operator to a base ref class and inherit from that base ref class in a derived ref class, the operator is recognized for that derived ref class:
#include "stdafx.h"
using namespace System;
interface class Base
{
public:
static int operator * (Base ^ it) { return 3; }
};
ref class Derived : Base
{
};
int main(array<System::String ^> ^args)
{
Derived ^ d(gcnew Derived);
int amt = *d;
Console::WriteLine(L"Hello World");
return 0;
}
The above compiles with an error of:
error C2440: 'initializing' : cannot convert from 'Derived' to 'int'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
But if one changes the line in the code above from 'interface class base' to 'ref class base', the code compiles and runs with no errors.
Does anybody know why this behavior occurs ?Edward Diener
|
|
|
|
|
Could it be because only a ref class can be assigned to a variable declared with the hat ^ operator?
|
|
|
|
|
I do not understand the reasoning of your answer. What does the hat operator have to do with my OP ? Edward Diener
|
|
|
|
|
I'm not 100% sure about this, but this is what I meant above:
When you declare your variable d , you are declaring it as a reference to a managed object by virtue of the fact that you are declaring it thus:
Derived ^d;
When you declare a class without the ref keyword, it becomes a value class.
You cannot assign a value class to a ref variable.
If you want your Base class without the ref keyword, then you must declare d without the hat ^ operator, thus:
Derived d;
|
|
|
|
|
A class without the 'ref' keyword in C++/CLI is a native C++ class. Nowhere in my OP did I create variable for the Derived class without the ^ symbol. Please look at my OP again. Edward Diener
|
|
|
|
|
You're right.
But this catches my eye:
Derived ^ d(gcnew Derived);
Change that line to:
Derived ^ d(gcnew Derived());
BTW, why don't you just say:
Derived ^ d = gcnew Derived();
|
|
|
|