|
|
but i want to call functions from class. dllimport calls only c style functions, it doesn't support c++ classes
|
|
|
|
|
I don't think you can do that.
You will need to convert the class into a COM component and then do a COM interop.
COM interop is what Microsoft recommends.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
|
Not true. You can export/import a class.
articles here: DLLs are simple: Part 2[^] and here http://msdn.microsoft.com/en-us/library/a90k134d.aspx[^].
On top of that you can demonstrate this by creating a DLL with the Visual Studio wizard. Create a Win32 project and select export symbols.
I missed the C# part of your question. You are posting in the wrong forum. You also phrased your question incorrectly, which mislead me. You used the terms "unmanaged class" and "DLL" and then threw in "the C# side."
Incidentally, if you "own" the C++ side, you can add the CLR switch to its project and use C++/CLI. (Frankly, I usually find it easier to convert the class in question to C#, but I have done what I just described.)
|
|
|
|
|
You should use COM objects to access C++ classes like that from .NET.
Life is a stage and we are all actors!
|
|
|
|
|
I apologize for my previous answer. I misread the original question due to him mixing terms.
That said, I still disagree somewhat--if he "owns" both sides, he can simply create the C++ DLL using C++/CLI.
|
|
|
|
|
As seen by my other answers, the phrasing of your question annoys me. The subject is "calling unmanaged class from DLL" and then you say you want to call "any class from unmanaged DLL." What is it? Are you wanting to call .NET from native C++ or call native C++ classes from .NET?
In the former case, you can host .NET in your C++ application (which is a lousy idea, but you can do it.) In the latter case you can convert the native C++ to C++/CLI and call it that way. I personally find it easier to convert the C++ classes to C# (and occasionally use a native, helper DLL with procedural APIs.)
On top of that you give a code snippet that makes no sense. If you have a C++ foo and a C# Foo, what do you care?
|
|
|
|
|
i want to call any class from native c++ into (managed-unmanaged) c#. i am looking for other ways except GUID.
|
|
|
|
|
|
I want to write shell programming in UNIX, alao i am new to unix. i have written very simple program for console
ISSUE:
I added some item in map as string int pair, now i am searching string read from commandline and i am unable to find it, but if i use same code with windows . i am able to do same.
Code is as follows
#include <stdlib.h>
#include <ctype.h>
#include <iostream>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <ctime>
#include <string>
#include <stdio.h>
#include <map>
#include <algorithm>
using namespace std;
map <string, int> m1;
int main(int argc, char* argv[])
{
m1.insert(map <string, int> :: const_iterator::value_type("cd",0));
m1.insert(map <string, int> :: const_iterator::value_type("dir",0));
m1.insert(map <string, int> :: const_iterator::value_type("pwd",0));
m1.insert(map <string, int> :: const_iterator::value_type("echo",0));
m1.insert(map <string, int> :: const_iterator::value_type("help",0));
m1.insert(map <string, int> :: const_iterator::value_type("quit",0));
map <string, int> :: const_iterator m1_AcIter, m1_RcIter;
typedef pair <string, int> Int_Pair;
if(argc == 1)
{
cout<<"Please enter unix command..";
}
else
{
string command;
command = argv[1];
map <string, int> :: const_iterator m1_AcIter, m1_RcIter;
m1_AcIter = m1.find(command);
if(m1_AcIter == m1.end())
{
cout<<"Didn't find unix command - "<< command<<endl ;
}
else
{
system(command.c_str());
}
}
map <string, int> :: iterator it;
for ( it=m1.begin() ; it != m1.end(); it++ )
cout << (*it).first << " => " << (*it).second << endl;
return 0;
}
now i am running this code
./a.out ls
and i received following output
Didn't find unix command - ls<br />
cd =>; 0<br />
dir =>; 0<br />
echo =>; 0<br />
help =>; 0<br />
pwd =>; 0<br />
quit =>; 0
but same code is working perfectly with windows.
|
|
|
|
|
I don't see a problem here. Your map table does not contain an entry for 'ls' so the program correctly reports it as not being found. Quite how this works on Windows remains a mystery - can you show the working sample?
|
|
|
|
|
Above code is working, But this code is not working
#include <stdlib.h>
#include <ctype.h>
#include <iostream>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <ctime>
#include <string>
#include <stdio.h>
#include <map>
#include <algorithm>
using namespace std;
map <string, int> m1;
string tokenizeReturnFirst(const string& str,const char& delimiters)
{
string token;
string::size_type lastPos = str.find_first_not_of(delimiters, 0);
string::size_type pos = str.find_first_of(delimiters, lastPos);
if( pos!=string::npos)
{
token = str.substr(lastPos, pos - lastPos);
}
else
{
token = str;
}
return token;
}
int main()
{
m1.insert(map <string, int> :: const_iterator::value_type("cd",0));
m1.insert(map <string, int> :: const_iterator::value_type("dir",0));
m1.insert(map <string, int> :: const_iterator::value_type("pwd",0));
m1.insert(map <string, int> :: const_iterator::value_type("echo",0));
m1.insert(map <string, int> :: const_iterator::value_type("help",0));
m1.insert(map <string, int> :: const_iterator::value_type("quit",0));
map <string, int> :: const_iterator m1_AcIter, m1_RcIter;
typedef pair <string, int> Int_Pair;
ifstream ifile( "test.bat");
if ( ifile.fail() )
{
fprintf(stderr, "Cannot open %s\n", "output_file");
return 0;
}
while (!ifile.eof())
{
string data_string ;
getline(ifile,data_string);
string command = tokenizeReturnFirst(data_string,string::value_type(' '));
cout<<"Searched string - "<<command <<endl;
m1_AcIter = m1.find(command);
if(!command.empty())
{
if(m1_AcIter == m1.end())
{
cout<<"Didn't find unix command - "<< data_string<<endl ;
}
else
{
cout<<"SYSTEM - "<< data_string.c_str()<<endl;
system(data_string.c_str());
}
}
}
return 0;
}
Input file test.bat file content
<br />
ls<br />
pwd<br />
echo<br />
aaa<br />
quit
now i tried to execute
Input
./a.out test.bat
Output:
<br />
Searched string - ls<br />
Didn't find unix command - ls<br />
Searched string - pwd<br />
Didn't find unix command - pwd<br />
Searched string - echo<br />
Didn't find unix command - echo<br />
Searched string - aaa<br />
Didn't find unix command - aaa<br />
Searched string - quit<br />
Didn't find unix command - quit<br />
Searched string -
but file contain this command but output is wrong.
|
|
|
|
|
Don't know what you're testing it on, but your code certainly works on Mac OS X 10.5.8.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
What line terminations does the file have? \n or \r\n? It makes a difference - if you've produced the files in Windows, then they're likely to have \r\n. Unix systems will read the \r as part of the command string, so the command you're looking for will be (for example) 'pwd\r'.
I've just tested that theory on my Mac (saved test.bat with Windows line-endings) and it reflects what you've seen.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
This code works fine on Windows. I cannot see what you are doing wrong, but it may be as mentioned by Stuart below.
|
|
|
|
|
yesh i resloved the issue.
it is due to file is generated by windows
so it contain /r/n so now i created file in unix system , now it resolved my issue. but how we handle such situation
|
|
|
|
|
Add something straight after the getline call to remove a trailing \r? Like this:
if (*data_string.rbegin() == '\r')
data_string.erase(data_string.length()-1);
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hint - you haven't got ls in your map!!!! You've got dir , which is the WIndows equivalent, but not ls .
When you add
ls,/code>, it works. I know, I've just run it on OS X, which is a Unix... <br />
<br />
<div class="ForumSig">Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p</div>
|
|
|
|
|
When we create an owner draw Listbox, We override DrawItem() and MeasureItem(). But this just draw item for Listbox. How to draw border for ListBox?
|
|
|
|
|
You mean you want to draw a custom border around your list control? If so, try handling the WM_NCPAINT[^] message.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
I wrote a Queue class in java with the method Add
public void add ( Object x )<br />
{<br />
items[rear] = x;<br />
rear = (rear + 1) % items.length;<br />
++count;<br />
}<br />
Now I'm trying to write it in C++. My problem here is I can't use rear = (rear + 1) % items.length;
Since I can't use items.length, what would that be equivalent to in C++?
Thanks in advance,
Jonig
|
|
|
|
|
You'd keep track of the allocated length of items yourself. (Yes, it's annoying that you can't get the allocated length in C++, even though it's available to library code.)
|
|
|
|
|
Or use any standard containers like std::vector rather than plain arrays.
|
|
|
|
|
Use the STL deque[^]
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|