|
This is just a stab in the dark, but possibly a typo? Maybe "Danial" should be "Daniel"?
|
|
|
|
|
|
Hi
I have written a code in C# to load functions in an unmanaged dll.
This is the code.
class Program
{
static unsafe void Main(string[] args)
{
int deviceNr;
char* Info;
int intMyReturnVal;
deviceNr = 0;
Info = null;
intMyReturnVal = sample_getinfo(deviceNr, Info);
}
[DllImport("opcard2lib.dll")]
private unsafe static extern int sample_getinfo(int deviceNr, char* Info);
}
and this is the API function description by dll supllier.
1. Sample_GetInfo
Prototype:
DLLReturnType
Sample_GetInfo (int deviceNr,
char* Info);
Parameters:
deviceNr is a number of found card in system
Info is handler for string with information about current card in system
Returns:
Returns 0 (zero) when success. Otherwise return an error code.
Description:
This function provide information about installed card in system. Information returned
in Info string looks like below:
„SN YY.SN rev. RRR", where:
YY – year of production
SN – serial number
RRR – firmware revision
The problem is that when I run this code I get the bellow error exception:
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
I have written this in VB.net to and get the same result.
I would appreciate your help.
|
|
|
|
|
The library function will store some data into the memory pointed to by Info so it needs to contain a valid address. You initialised it to null which is zero, an invalid address. You need something like:
char* Info;
Info = new char[128];
Use the best guess
|
|
|
|
|
thanks dear friend.
I will check it soon.
|
|
|
|
|
I notice that you also posted this question at Problem with P/Invoke[^] in Quick Answers. Please post in one forum only.
Use the best guess
|
|
|
|
|
it gives this exception
cannot implicitly convert from char[] to char*
|
|
|
|
|
Please show your code, what I provided compiles successfully, so i can only assume you have done something different.
Use the best guess
|
|
|
|
|
I just added this line to code as you mentioned.
Info = new char[255];
|
|
|
|
|
Please show the code block where the error occurs, indicate the line in error and the exact text of the error message.
Use the best guess
|
|
|
|
|
hi dear Richard MacCutchan
I think i have problem when the argument of the function is of pointer type.
I checked functions with no pointer and there was no problem.
As I searched the net I saw that something about Marshaling but I don't know how to implement it.
Is this the way or you suggest something else?
Thanks
|
|
|
|
|
Nooredin wrote: I think i have problem when the argument of the function is of pointer type. I checked functions with no pointer and there was no problem. That does not make sense, it just means that your function call does not match the function definition.
As to the remaining issue, if you have a problem with the code then you need to show us the code and any error messages you receive. If you need help in understanding how to use P/Invoke then I would suggest reading this white paper[^].
Use the best guess
|
|
|
|
|
hi dear Richard MacCutchan
you have helped me a lot with this. I appreciate it.
the most unbelievable problem with that dll was some functions did not included in the dll but described in manual and unfortunately i was focused on them
I have mostly done with this except introducing char array pointer to dll.
I wish I can do it soon.
By the way, thanks for your kind help.
|
|
|
|
|
Hi All,
My application is hosted in four servers. I wanted to create a tool that will be installed in any one of those servers. Purpose of this tool is to monitor App pool crash in each server and trigger a mail.
Could someone let me know how we can write this code in .Net?
Cheers
A.M.Jegan
|
|
|
|
|
|
amjegan wrote: Could someone let me know how we can write this code in .Net?
The application does something.
Your app periodically verifies that it is continuing to do something. If it isn't then send the email.
The specifics of that depends on what the application does.
And if the servers are load balanced and you really want to test each then you need a way to specifically kick off the task in each. So if each responds to some IP trigger then you need a way to independently send that trigger to each. Router/firewall and dns resolution might be involved to get that to work.
|
|
|
|
|
I have created xml file with node element and child elelement. I have created asp.net application using VS2008 and am unable to write to that XML file. Its giving already another process is using. Access dinied.
How to do this.
If anybody knows please reply me.
Thanks in advance.
|
|
|
|
|
Do not post your question in different places.
|
|
|
|
|
If the file is locked by amnother process you can't write to it. It's that simple. You have to wait for the other process to let go of the file.
If the process is the very same one you're writing, well, then you've done something wrong where you didn't close the file. You can't have more than one exclusive writer to the same file.
|
|
|
|
|
NO I have created application that displays a message on desktop always using that XML file and I need to change that XML message so that application keeps message changing on desktop.
how to do that
|
|
|
|
|
By disposing of the StreamWriter perhaps that has the file locked? It's obviously your app that's keeping it locked. That means you're probably not disposing something correctly.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
That's not at all what you described.
If the desktop application is only reading the file, then you can open it with a FileStream[^], specifying a Share.ReadWrite, allowing the ASP.NET application to Write to the file.
After you get the FileStream, you pass that object to your Xml reader.
The problem is that while you're reading it, the ASP.NET might write to it at the same time, corrupting the data you read, so you'll have to handle this case.
The ASP.NET code will have to be modified to open the file with Shared Read access so your desktop app can open it at the same time.
|
|
|
|
|
Good explanation.
Previous -> Read "CLR via C#" by Jeffrey Ritcher.
Current -> Exploring WCF thru Apress' "Pro WCF" by Chris Peiris and Dennis Mulder.
Next -> Need to read "The Art of Computer Programming" by Donald E. Knuth.
|
|
|
|
|
Hello guys, I have a prob with my typed DataSet, applying its query on SQL it makes fraction of second, running the program and since the query embedded in the DataSet it gives TIMEOUT!!!!
here is my query:
SELECT i.item_id, i.sequence, i.item_name, od.buy_price, od.sell_price,
SUM(od.quantity) AS sum_qty,
l.location_name, oh.usr_login,
CASE i.is_composite_item WHEN 1 THEN "anything" WHEN 0 THEN "something" END AS remarks
FROM item i, operation_detail od,operation_header oh,location l
WHERE
i.item_id=od.item_id and i.sequence=od.sequence and
od.operation_header_id=oh.operation_header_id and
oh.location_id=l.location_id and
(oh.operation_type_id = "anything") AND
(oh.operation_date >= @date_from ) AND
(oh.operation_date <= @date_to ) AND
(i.item_id >= @item_id_from OR @item_id_from = 0)
AND (i.item_id <= @item_id_to OR @item_id_to = 0)
AND (l.location_id = @location_id OR @location_id = '0')
AND (i.is_raw_item = 0)
GROUP BY i.item_id, i.sequence, i.item_name, l.location_name,
oh.usr_login, od.buy_price, od.sell_price,i.is_composite_item
order by i.item_id, i.sequence,l.location_name
|
|
|
|
|
The fact that it runs under a typed dataset will not make it that much slower. What's your timeout set to? Are you sure you're querying the same database from code as you're executing directly? How much data is there in the resultset?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|