|
|
Hi,
I have a C++ class that is compiled as a DLL.
now I would like to import it to my C# program.
I know how to import function, but what should I do for importing the class so I can in my C# program create an instance of this class?
Thanks,
|
|
|
|
|
Unless it is managed C++ you cannot import the class. If it is managed C++ then what you have as an Assembly which can be added by adding a reference to it in the project and by putting a using myNamespace at the top of the C# file you want to use the managed C++ class in.
|
|
|
|
|
Thanks, but how do I know if it's managed C++.
It was written with Visual Studio 2005
|
|
|
|
|
hi,
You could try adding a reference to the dll to your c# project. It will fail if it is not a managed assembly or COM component.
Another way would be to try to open the dll with the MSIL disassembler. Again this will fail if there is no CLR header.
Alan.
|
|
|
|
|
Something which just came to mind. Would it be possible to have a function which returns a pointer to an instantiation of the class? So would something like this work?
//C++
extern "C" MyClass *GetInstantiation(void);
//C#
[DllImport("MyFile.dll")]
public static extern IntPtr GetInstantiation();
|
|
|
|
|
yes its possible
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
|
I usually create a bridge written in C++ managed which creates one managed class and namespace that could be later imported into C#, but underneath this managed C++ class works with that actual and normal C++ class any way it is expected to work with this class, either I compile them together or I import dll and call this class internally.
This bridge serves several good purposes: to test what actually I need in C# from that C++ class. Only those things pass the bridge. Second the bridge is an excellent place to check if parameters are passed correctly and if some of them have to be arranged differently: pointers, arrays... all need different treatment in C# and C++.
If you don't have this bridge, but you directly call a C++ procedure from C# then you have to think about this inside C# code every time you call a specific C++ function. And then if you want to use the same C++ class again, the same problem. With bridge you just import it and everything is tested.
|
|
|
|
|
Hi all,
How can i find out process path?
i am using following code for getting process file name. i need to get the path of that file also. Can any one help me??
Process[] arrProcesses = Process.GetProcesses();
for (int i = 0; i <= arrProcesses.Length - 1; i++)
{
Process objProcess = arrProcesses[i];
if (objProcess.ProcessName == "WINWORD" && !(objProcess.MainWindowHandle == IntPtr.Zero))
{
string FileNameDefault = objProcess.MainWindowTitle;
string[] str1;
str1 = FileNameDefault.Split('-');
// System.IO.Path pt=objProcess.exe
FileNameDefault = str1[0];
}
}
Regards
Lijo
|
|
|
|
|
objProcess.MainModule.FileName
Edit: Suggestion: If you are searching for only Winword processes you can use Process.GetProcessesByName to avoid the loop and checking for the particular process name
modified on Monday, March 2, 2009 9:46 AM
|
|
|
|
|
ABitSmart wrote: avoid the loop
GetProcessesByName() returns an array, just like GetProcesses() does; it probably will be a shorter array, but you may still want to enumerate it.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Sunday, June 12, 2011 8:58 AM
|
|
|
|
|
My intention was to make the OP aware about GetProcessesByName. Thanks for your comment
(edited my comment)
|
|
|
|
|
Hi,
I have using sockets to communicating with our client applications. In the server application Listener i mentioned backlog 200 but most of the times the connection queue holds below 100 requests only. In this case some times when client try to connect .Net throw an error which says the queue was full. After that Listener will not take any new connections and it just close socket immediatly.
ListenSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint ipLocal = new IPEndPoint(IPAddress.Any, 4098);
ListenSocket.Bind(ipLocal);
ListenSocket.Listen(200);
ListenSocket.BeginAccept(new AsyncCallback(OnClientConnect), null);
Error: [OnClientConnect]->
An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full
I dont understand what is happening there............
Please give me the solution....
friendly,
ranandbe
|
|
|
|
|
Hi All,
I need to insert a char in the beginning of the XML file. Char is “?”.
Tried with binary writer but it inserted few extra characters also.
Has anybody faced similar issue?
Or is there any other way to do it ?
Thanks & Regards,
Maan
|
|
|
|
|
Member 578189 wrote: I need to insert a char in the beginning of the XML file. Char is “?”.
If you insert ? to the beginning of XML file, XML file will become invalid and you will not be able to parse it. Are you trying to add the <?xml version="1.0" encoding="utf-8" ?> line?
|
|
|
|
|
Navaneeth,
my original line is
and i need ?<xml version="1.0" encoding="utf-8">;
small background about what i am doing:
I am creating a xml file in console and trying it save it as XML.
And when i use this XML it gives me an error because char "?" is missing.
|
|
|
|
|
Member 578189 wrote: I am creating a xml file in console and trying it save it as XML.
Use the XML manupulation classes like XMLDocument . It has got a Save method which writes a XML file.
|
|
|
|
|
Dear All,
i am using DataRow for insert update query for records in c# and this error below what should i do?
Update requires a valid Insert Command when passed DataRow collection with new rows
what i have to do for insert record ?
Is this is good approach to insert and update data in tables.
Kindly brief me.
Sajjad Lashari
|
|
|
|
|
Sajjad Leo wrote: what i have to do for insert record ?
Follow the instructions in the error message. You need to create an Insert command on the SqlDataAdapter.
Sajjad Leo wrote: Is this is good approach to insert and update data in tables.
In my opinion? No, never.
|
|
|
|
|
Hi Dear,
You replayed good but i am still not able to get my goal,
can you guide me if i am inserting a record what steps should i follow please send me complete steps.
Sajjad
|
|
|
|
|
Sajjad Leo wrote: please send me complete steps
You have not sent me complete detail of what you are wanting inserted and where.
Basically, create a SqlConnection object, create a SqlCommand object, Open the connection, ExecuteNonQuery on the command object and then Close the connection.
Your command should preferably use stored procedures in the database.
|
|
|
|
|
Dear,
I solved that problem now i using a sql query for retrieving a record from a student table i am selecting class from drop down like Class A and then the data of class A name of students will display in list box and then i select one name of class A from list box and want to display data in grid view i am writing query like
string rec = "select * from student_biodata where student_name = '" + liststudent.Text + "' ";
But one problem is that if i am selecting name like 'a' then two record displayed in grid view like 'a' of class A and 'a' of Class B so what should i do please guide me correct query as i can get only one record.
Thanks
Sajjad Ali
modified on Tuesday, March 3, 2009 5:22 AM
|
|
|
|
|
What is the best method if I want to limit The number of connections a server accepts?
I suppose this is not really a good way to achieve what i want:
while(true)
{
if(numberOfConnections < 100)
{
Socket s = listenerSocket.Accept();
...
}
else
{
Thread.sleep(1);
}
}
Has anyone a better idea how to keep the cpu down?
|
|
|
|
|
I's probably use a ManualResetEvent instead of sleeping a thousand times per second - it's more accurate and less of a hack.
ManualResetEvent m = new ManualResetEvent(true);
while(true)
{
m.WaitOne();
if(numberOfConnections < 100)
{
Socket s = listenerSocket.Accept();
...
}
else
{
m.Reset();
}
}
And somewhere at a place where you close the connections, do m.Set() if the number of connections is lower than 100 again.
But beware, I just woke up, so don't trust this code or even this idea
|
|
|
|