|
|
Though I don't like that solution, but here is a link to something that may help. Click here[^].
PS.
If you are mulithreading, then getting this exceptions means that you've done something wrong, and ifnoring it isn't quite the best thing to do.
Regards
|
|
|
|
|
LOL Great minds think a like
Its not threading its quite procedural, so this should suffice.
I'll see if it blows up when I get it into production. Then it might be back to the drawing board.
/TH
|
|
|
|
|
There is a program calling a C++ dll named "ffisamp.dll".
The C++ code is as follows:
*****
//Simple C function that just puts something in a string
// and returns the length of that string both as the RC and as a param
// Keeping the C interface as simple as possible.
__declspec( dllexport ) int PopulateString ( char *FormsBuffer, int *BuffLen)
{
int LocalLength;
strcpy(FormsBuffer,"A Fixed string from within the C program");
*BuffLen = strlen(FormsBuffer);
LocalLength = strlen(FormsBuffer);
return LocalLength;
}
*****
I need C# code that will compile to a dll that mimics the sample dll such that no modifications will need to be made to the calling program. I need to be able to just replace the old dll with the new one.
I am most perplexed that the C++ method is not in a class. That might be that the source code is just a snippet of the whole dll's source code... since it comes from a sample, but I have the impression from the documentation that is all of it. Here is a link to the article I am working with. I am trying to communicate with an Oracle 10g form using methods to call C functions.
http://www.oracle.com/technology/products/forms/htdocs/webutil/howto_ffi.html[^]
I've tried a few things, but so far the calling application doesn't even find the function.
I am not familiar with C++, MFC etc... so I am sure I am missing some fundamentals.
|
|
|
|
|
AFAIK that's not possible.
C# is managed code, while C++ is unmanaged code. Data and object marshaling in both is very different -not to mention the structure of the dll file, and the method of function exporting-.
Regards
|
|
|
|
|
While I don't know much about C# I am aware that MS went to some effort to make managed code and native code interoperate. I’d be willing to bet it is possible.
Steve
|
|
|
|
|
Stephen Hewitt wrote: I’d be willing to bet it is possible.
If you do, then why didn't you tell us how to do it!
Yes, it's possible somehow, but not in his scenario. You may mean the COM wrapper of DotNet that enables you to make your objects COM visible. He wants to make a C# dll for a program that references a C++ dll without COM, and my bet is that the program doesn't expect a managed code either. Also note that the function doesn't belong to a class which is not allowed in C#.
Regards
|
|
|
|
|
Here's what I said:
Stephen Hewitt wrote: While I don't know much about C# I am aware that MS went to some effort to make managed code and native code interoperate. I’d be willing to bet it is possible.
Nader Elshehabi wrote: If you do, then why didn't you tell us how to do it!
Isn't the answer to this question obvious? "I don't know much about C#". I don't know how, it's just my opinion that it’s possible. What’s more, I’d wager it’s not that complex.
Steve
|
|
|
|
|
As already explained by others, C# can only produce managed code, while your sample is an unmanaged DLL. There are several ways to implement managed-unmanaged interoperability, but there is no simple solution for what you want to do.
One idea that come to my mind requires the creation of two DLLs:
One unmanaged C++ DLL that exports your required method and transforms it into a COM method call. And a COM server DLL that provides the method consumed by the first DLL. The second DLL can be written in C# as managed DLLs can be designed to be callable by COM clients (CCW).
Regards,
Tim
|
|
|
|
|
Well, I actually expected it was the case that I could not fully duplicate the external behavior of a C++ dll, but I wanted to make sure.
The C++ wrapper dll occurred to me and would be possible since we have C++ developers, but it is not a good solution.
Ultimately the problem was solve in another manner. We are communicating through he standard output stream and it works great.
Thanks for everyones comments.
|
|
|
|
|
I'm not sure if this is what you want, but it might be helpful:
Interop[^]
V.
I found a living worth working for, but haven't found work worth living for.
|
|
|
|
|
I would like to add a new row in my datagrid, which is the summary of the other rows in the datagrid. Much like a "Total" row in excel spreadsheet. Thing is, when my user sorts the datagrid by clicking one of the column headers, I would like this Summary row to stay at the bottom. Have done my research but the only thing I came across when it comes to sorting is the AllowSorting() method.
Also, it would be great if I can have my first column also frozen when I scroll to the right, such that the user will be able to see to which row header the value belongs to without having to scroll back to the left everytime.
Thanks in advance!
I am a SysAdmin, I battle my own daemons.
|
|
|
|
|
PS I know how to add another row to the datagrid. What is proving to be tricky is making this extra row stay at the bottom when the column is sorted by clicking the header. Anyone got any idea?
Thanks!
I am a SysAdmin, I battle my own daemons.
|
|
|
|
|
In the ItemDataBound:
Try something like this:
switch e.Item.ItemType
{
case ListItemType.Footer:
e.Item.Cells(0).Text = "Sum : " +FigureSum(internalSum);
}
|
|
|
|
|
I've been looking around for a book or a site that does a good job explaining how to create a custom control. I would like that it cover issues like efficiency and usage of current .Net technologies. I haven't been able to find any information out there except for a book that was written while .NET was in beta. Anybody have suggestions?
|
|
|
|
|
Mr. Rogers wrote: Anybody have suggestions
Ummm... CodeProject[^]?
PS.
Take a special look at hit 5.
Regards
|
|
|
|
|
I found that "Windows Forms Programming in C#" to be an overall excellent book on intermidiate to advanced levels. Written by Chris Sells, published by Addison Wesley.
ISBN # 0-321-11620-8. He covers Custom controls in much detail!
Good Luck
|
|
|
|
|
Hi everyone, i'm a little bit stuck.
While i was amazing myself discovering the dateset design wizard (which means that me querys methods will get waaaay shorter now ), i'm not able to insert a row in the Access database.
I'm using a query to load a treeview, which works just fine:
<br />
<br />
private void GenerateTreeview()<br />
{<br />
treeView1.Nodes.Clear();<br />
onAirDataSetTableAdapters.contenidoTableAdapter contAdap = new Loteria.onAirDataSetTableAdapters.contenidoTableAdapter(); <br />
DataTable tabla = contAdap.ObtenerDatos(); <br />
DataView dataViewHijos = new DataView(tabla);<br />
<br />
and so on....<br />
<br />
}<br />
now, i want to add a node on the treeview, and store that into the database table where I have my items. I tried this on a try/catch/finally, just to make sure i'm not getting any errors. I call generateTreeview() function on finally, to reload my Treeview.
<br />
try<br />
{<br />
onAirDataSetTableAdapters.contenidoTableAdapter contAdap = new Loteria.onAirDataSetTableAdapters.contenidoTableAdapter();<br />
contAdap.InsertarCategoria(dlg.nombre, nodoPadretempID); <br />
}<br />
catch (OleDbException ode)<br />
{<br />
MessageBox.Show(ode.ToString(), "Error de Conexion con base de datos");<br />
}<br />
<br />
catch (Exception er)<br />
{<br />
MessageBox.Show(er.ToString());<br />
}<br />
<br />
finally<br />
{<br />
GenerateTreeview();<br />
}<br />
<br />
Everything works ok, i get the updated Treeview while running my app, but the database doesn't get updated.
I restart the app and i get the same initial treeview, and of course, no changes are being performed on the mdb...
PLEASE HELP!!
thanks for eveyones time
kiweed
|
|
|
|
|
Does any one of you have an example to connect to Oracle DB on Unix machine using C# service application ? Any hint or idea would be of great help....
Srinath
|
|
|
|
|
Have you used the OracleProvider?
|
|
|
|
|
Yes..
Srinath
|
|
|
|
|
Hi,
I've got a List object containing listviewitems. And i have a few items added to my listview control.
With the findIndex() method i wanna search for an index of an element in the List object and add another element as a subItem to that element.
The problem is, i don't understand the arguments FindIndex() expects.
Can somebody give me an example?
Thanks in advance!
|
|
|
|
|
MSDN topic for List.FindIndex Method[^]
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
The MSDN information is what I would read to get the information, as well as some sample code, though I do have some trouble understaing it sometimes. From my understanding (still learning) the FindIndex takes a predicate. The predicate is basically a function that accepts a value of whatever type your list contains, does a calculation, and returns true or false.
So let's say I have a List of INTs. If I wanted to search for the first occurance of a number greater than 5, I would create a function like this:
<br />
public bool IsGreaterThan5(int i)<br />
{<br />
if(i > 5)<br />
return true;<br />
else<br />
return false;<br />
}<br />
Then, when I want to find the first instance in my INT list that is greater than 5, I do this.
<br />
int FirstOccurance = myIntList.FindIndex(IsGreaterThan5);<br />
There are also other variations of the FindIndex function that you can use:
List.FindIndex(int32, predicate) - Limits the search range from the int32 element to the end of the list
List.FindIndex(int32, int32, predicate) - Limits the search range from int32 to int32.
Hope that helps!
|
|
|
|
|
Hi guys,
I've read the msdn library for both code sample of this method and the documentation about it.
But i didn't understand it very well.
I've also searched with google for another example...
This is what i've tried:
// convertedString is an int
int indexOfNumber = this.listViewItems.FindIndex(FindIndexOfListViewItem(convertedString);
private int FindIndexOfListViewItem(int index)
{
for (int i = 0; i < this.listViewItems.Count; i++)
{
string currentItem = this.listViewItems[i].ToString();
//this.number is the item i wanna add as a subItem
if (currentItem == this.number)
{
return i;
}
}
return -1;
}
These are the errors i get:
The best overloaded method match for 'System.Collections.Generic.List<system.windows.forms.listviewitem>.FindIndex(System.Predicate<system.windows.forms.listviewitem>)' has some invalid arguments
Argument '1': cannot convert from 'int' to 'System.Predicate<system.windows.forms.listviewitem>'
What am i doing wrong?
Thanks in advance!
-- modified at 3:26 Thursday 11th January, 2007
|
|
|
|