|
|
thank you very much for your help Richard. I found the error, and my program works.
error is not in the code that I've written here
modified 27-Mar-14 6:53am.
|
|
|
|
|
Please help! Even I am experienced in C++ and C#, I am new to C++/CLI.
I have written a simple C# program using WinSCP library. I know how to do it in C# as there is already an example (http://winscp.net/eng/docs/library#csharp[^])
I try to convert but I do not get any success.
#using "WinSCPnet.dll"
using namespace System;
int main(array<System::String ^> ^args)
{
try
{
Console::WriteLine("Staring...");
WinSCP::SessionOptons ^ sftpSessionOptions = gcnew
WinSCP::SessionOptions::SessionOptions (
WinSCP::SessionOptions::Protocol =
WinSCP::Protocol::Sftp,
...
);
...
}
But I get this error:
Error c2061: syntax error: identifer '{ctor}'
why? Please help in the translation.
Yes I have made sure it compiles with '/clr' option.
|
|
|
|
|
|
Richard,
Thanks for your help. I get it. The thing is when I mouse over the new SessionOptions in this line in the C# program,
SessionOptions sessionOptions = new SessionOptions {
Protocol = Protocol.Sftp,
I see SessionOptions.SessionOptions(). With that in mind, when I do the C++ program, I convert that line to:
WinSCP::SessionOptions ^ sftpOptions = gcnew
WinSCP::SessionOptions::SessionOptions()
sftpOptions->Protocol = WinSCP::Protocol::Sftp;
As you can see, that (WinSCP::SessionOptions::SessionOptions()) is not a valid call. I change that to gcnew WinSCP::SessionOptions() and it works! Thanks.
|
|
|
|
|
Hello,..
Hey i dont know how u willtake my suggestion but , i have an idea for u
Use C# to C++ convertor.. it may help you..
int Example::Main()
{
try
{
SessionOptions ^sessionOptions = gcnew SessionOptions {Protocol = Protocol::Sftp, HostName = "example.com", UserName = "user", Password = "mypassword", SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"};
using (Session session = new Session())
Session ^session = gcnew Session();
try
{
session->Open(sessionOptions);
TransferOptions ^transferOptions = gcnew TransferOptions();
transferOptions->TransferMode = TransferMode::Binary;
TransferOperationResult ^transferResult;
transferResult = session->PutFiles("d:\\toupload\\*", "/home/user/", false, transferOptions);
transferResult->Check();
for each (TransferEventArgs ^transfer in transferResult->Transfers)
{
Console::WriteLine("Upload of {0} succeeded", transfer->FileName);
}
}
finally
{
delete session;
}
return 0;
}
catch (Exception ^e)
{
Console::WriteLine("Error: {0}", e);
return 1;
}
This ur sample C# code to C++/CLI.
|
|
|
|
|
I try that converter, but when I compile, there are problems. Thanks for the suggestion.
|
|
|
|
|
Hi, i am working on a project using C and C++.
But now i have to use lil bit of C# code in it.So i made a sample application , converted all the c# code to managed C++/CLI.I changed the properties of sample app to Clr support.It worked fine.
But in my current project, i have some pure c classes also. So when i was changing the property of my project to CLR , it gave me error of xyz.c file cannot convert into \clr.
I dont know wat to do?i cannot convert xyz.c class into xyz.cpp
Can anyone suggest what should i do... Is it possible that i mange to use mannaged c++ also and i still donot have to convert the whole project into CLR.
|
|
|
|
|
You could convert the C code into a DLL which you can then access via P/Invoke from the CLR portion. Unfortunately you cannot convert pure C code to CLR.
|
|
|
|
|
Hi,Thanks for the reply.
I managed to do it by adding a new CLR class and putting all my C Sharp code to it.Automaticaly VS
ask me that wether i would like to convert by my code to CLR.Then it converts all my code to CLR without giving any compile error .
Regards
Shubh
|
|
|
|
|
Hi Richard .. I posted my problem i tried diffrent ways to solve it..like i told you that i found a temporary way to resolve my problem.
But that is not proper solution.
You know what that now i am thinking to use my CLI/C++ code as dll .To call the function in that dll, do i need a wrapper class in my unamanged c++ code .If yes then can you give me an idea or post to implment it.I havenot used wrapper classes before.
Is there any other way to call dll functions.Need your guidance.Thanks in advance.
|
|
|
|
|
As I suggested before, you could just make all your unmanaged copde into a standard DLL. You can then access the functions directly via P/Invoke[^]. I am not exactly sure what you are trying to do with the C code, and whether it would not be better just to convert it all to C#.
|
|
|
|
|
Hey i dont think ,i made my point clear to you.Actually this thing is completely new to me.Thats why i am unable to explain it corectly.
I have unmanaged c++ code.
But now in that i need to use some of the managed i.e C++/CLI code.
That is my main problem .
I tried to search solutions on internet but these solutions made me more confused.
One of the solution said , i should make dll of the managed code .Then i should make one wrapper to call the functions of the dll.Should i do that.
Can't i directly use the functions of dll in my c++ unmanged code like withe help of GetProcAddtress()
without any wrapper class.I am new to all this.
Please Help.I need it .
|
|
|
|
|
I'm afraid it is still not clear exactly what you are trying to do and why you need to mix managed and unmanaged code. I have already explained that you can use the functions of an unmanaged DLL in managed code by using the P/Invoke mechanism (link given in my previous answer). If that does not, or will not work, then you need to give an example of your code and explain what the problem is.
|
|
|
|
|
Okay , i will tell you.What is my problem.
Actually i need to use powershell apis , in my c++ code.As i need to find out the no .of servers in my appfabric cluster.
So the challenge was how to acess powershell in c++ code.
I had one c# code in which i was able to acess powershell properly.
It gives me every information i need to find out..Like wether the appfabric service is running or not.How many servers in cluster.All the info.
Now as my code is in c++ , my biggest challenge is using the c# script in c++,because that
scripts works wonder for me.
So to use that i converted whole of C# code into C++/CLI so that i can use it in my current unmanged c++ code.
Now the problem is adding that C++/CLI code into UNMANAGED CODE so that i can acess powershell in c++.
How to do that mixed mode programming?
|
|
|
|
|
|
Hi,
I am looking for passing unsigned int* to managed C++ app
Ex:
Native C++:
void func(unsigned int * data)
{
//Here I have access to managed C++ class and I would like to know how to pass data to this class
managedwrapper->managedFunc( need to pass data)
}
ref class ManagedWrapper
{
managedFunc(get the data here)
{
//how to get the data here.
}
}
Thanks,
Paul
|
|
|
|
|
|
Hello,
I'm maintaining a previous system with VC++2003, and have to add more functions. I deveoped them with C# DLL. But now I can't call C# DLL from VC++ code.
pasted some code piece as below:
------------------------
c# part:
using System;
namespace MyCSClass
{
public class CSClass
{
public CSClass(){}
public void Print(){
System.Console.Writeline("Hello, I'm in CSClass");
}
}
}
--------------------
C++ part:
#using "..." //the DLL
using namespace MyCSClass;
void CPlus::CallCSClass()
{
CSClass ^ obj = gcnew CSClass();
obj->Print();
}
-----------------
The error is:
error C2143: Syntax error: missing ";" (before "^")
error C2065: "obj" undefined.
error C2227: "->Print" .....
Above is my translation, orginal is below:
error C2143: 语法错误 : 缺少“;”(在“^”的前面)
error C2143: 语法错误 : 缺少“;”(在“^”的前面)
error C2065: “objAuthen” : 未声明的标识符
error C2227: “->Authenticate”的左侧必须指向类/结构/联合类型是“'unknown-type'”
Anyone can help me? Thanks!
Code Project
|
|
|
|
|
Based on the compiler errors, it appears that the C++ file is not getting built with the /clr option. Check the project build properties to make sure CLR support is turned on.
Another thing to check is that you've added a reference to the C# assembly.
John
|
|
|
|
|
Yes, I'm sure turned on /clr. the building command line:
/O2 /AI "C:\git-hub\im-server\emc2s\MyTestInterop\Release" /AI "Release" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FD /EHsc /MD /GS /Yu"stdafx.h" /Fp"Release/MyTestInterop.pch" /Fo"Release/" /Fd"Release/vc70.pdb" /W3 /nologo /c /Wp64 /Zi /clr /TP /FU "C:\git-hub\im-server\emc2s\EMLdap\obj\Release\EMLdap.dll" /FU "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\mscorlib.dll"
Another, I'm sure added C# assembly in reference.
Anyother ideas to resolve it?
Code Project
|
|
|
|
|
Perhaps open your assembly with ILDasm or DotPeek and make sure the class is exported properly. Can you access it from another C# solution?
|
|
|
|
|
Yes, I tried in DotPeek, it works well. Also it can be called in other C# project.
Any other ideas?
Code Project
|
|
|
|
|
plz give the source code for medical store management
|
|
|
|
|