|
Hi James if want to pass same vaules to multiple times just save that values in cache and pass them when it required
|
|
|
|
|
Hi,
I have a 'C' API with signature as :
int Init(myStruct* struct, void** pHandle);
This pHandle is to be given as input in subsequent APIs.
My problem is that I have to access this in C#.
Any ideas how to do this ?
|
|
|
|
|
This can be done with p/Invoke. You'll find a lot of examples on this if you google.
Good luck!
|
|
|
|
|
See here[^] on MSDN, which explains the mechanisms and the things to be aware of when communicating between managed and unmanaged code.
txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
Hey Richard,
thanks for the reply. I have added some more explanation in my query. Can you have a look & let me know if it is OK or not ?
Thanks
|
|
|
|
|
Some more details :
'C' code :
-----------
int Init(myStruct* struct1, void** pHandle)
{
<...some code...>
*pHandle = sess_open(struct1, &session);
<...some code...>
}
'C#' code :
-------------
Declaration:
--------------
[DllImport("My_C_Library.dll")]
public static extern int MY_CSHARP_INIT(myStruct* struct1, ref System.IntPtr[] Session_pp);
Implementation:
----------------
public int MY_CSHARP_INIT(myStruct* struct1, ref System.IntPtr[] Session_pp)
{
int ret_val = Init(struct1, ref Session_pp);
}
-------------------------------------------------------------------------
This gives a Exception as "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
-------------------------------------------------------------------------
Any help appreciated.
|
|
|
|
|
You are trying to pass a pointer to a C# (i.e. managed) struct as an unmanaged reference, which will not work. You need to look at the marshalling options to see how the C code can access your C# objects. I have a suspicion that you cannot do it this way, but would need to convert your struct to some sort of basic array for the unmanaged (i.e. C) code to be able to access it.
txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
Hi,
two parameters using pointers, that is two potential problems. Try to split the job in halves, if you own the native code, experiment with a single parameter first.
For the struct pointer, I would opt for ref myStruct .
For the array of pointers, if the managed side does not NEED to know it is an array, just make it an IntPtr ; if it must operate on array elements, the only easy way I know of is by:
- somehow knowing the element count (if need be, add another method to obtain it from the native world);
- then allocate the array on the managed side;
- then pass its pointer to the native world, which I prefer to handle with a GCHandle, GCHandleType.Pinned, AddrOfPinnedObject.
Conclusion: you may not even need unsafe code.
|
|
|
|
|
hi i hava a groubox contain 5 textbox control and i want to empty the all textbox i'm having hard time to solve pls any idea..
|
|
|
|
|
And what have you tried? It's not that difficult.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Try this
foreach (Control ctl in groupBox1.Controls)
{
TextBox txt = ctl as TextBox;
if (txt != null)
{
txt.Text = string.Empty;
}
}
Life's Like a mirror. Smile at it & it smiles back at you.- P Pilgrim
So Smile Please
|
|
|
|
|
|
|
Sam205 wrote: force the worker thread to wait while each event gets processed
what do you mean by "the worker thread"?
The main thread (a.k.a. GUI thread) is the one executing event handlers such as a Button_Click() method. When you want extra threads, you create them by instantiating Thread class, or by calling ThreadPool methods, or by instantiating BackgroundWorker class. All of them are supposed to:
1. not interfere with the main thread
2. not touch GUI Controls, as only the main thread should be allowed to touch them.
Getting another thread to access the Controls anyway requires a special technique as described here[^] . When Control.Invoke gets called, the caller effectively will be blocked until the GUI thread has executed the invoked method.
I hipe that is what you need.
|
|
|
|
|
|
Sam205 wrote: so they are processed sequentially
Is that not happening?
|
|
|
|
|
If the event handler is in another thread, then no, it doesn't.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Yes and no. Don't they all start out on the GUI thread and if he chooses he can spin off threads to do other stuff? But the messages all come into the pump in order and the events fire in order, yes?
I don't see how things would happen out of order unless he did something he didn't mean to do.
As with your other response; why spin off a thread if you don't want asynchronous processing?
At any rate, I don't understand the question.
|
|
|
|
|
You could suspend the thread at the beginning of the event handler, and continue the thread at the end of the handler. But if you do that, you've essentially eliminated the benefit of using multithreading.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
is it possible to use XML file as data source for Microsoft Reports Viewer? How?
|
|
|
|
|
Creating Data Sources for a Report[^]
"Default data processing extensions are available for SQL Server, Analysis Services, SQL Server Integration Services, Oracle, SAP NetWeaver® Business Intelligence, XML, ODBC, and OLE DB."
Seriously, learning to use a search engine will help you a great deal
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I want to know how can I associate a file extension with my application? and when it's associated in Windows how can I make the file with that clickable so when the user clicks it then my application receives it? do I have to pass as arguments?!
|
|
|
|
|
Are you in China? Is Google restricted for you?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
hahaha.. nice
i already did google but i can only fine associating file during deployment and what i want is to have it part of my application in the Options form?
|
|
|
|
|