|
You need to Marshal the information before using it.
1. Allocate memory in a buffer using the Marshal.AllocateCoTaskMem(bufferSize) or Marshal.AllocHGLobal(bufferSize).
2. Pass the buffer (not your local C# structure) to the dll function.
3. Convert the buffer to your local structure using Marshal.PtrToStructure(buffer, yourStruct)
4. Then use the 'yourStruct' in your C# code to access the handles etc.
5. Release the buffer that was allocated accordingly.
Look at the following articles explaining how to do it.
a. www.codeproject.com/csharp/csenumnetworkresources.asp
and
b. The Microsoft MSDN help. It can be found in the following dirctory tree under MSDN.
.NET Development->.NET Framework->Programming with the .NET Framework->Interoperating with Unmanaged Code->Interop Marshalling->Marshalling Data with Platform Invoke->Miscellaneous Marshalling Sample->Void Sample
I hope this helps
RobVai
|
|
|
|
|
Hi,
I have the follwing problem :
When doing field level validation, I use the following code the check whether a value entered in a text box is actually an integer :
try
{
int.Parse (this.textBox1.Text);
}
catch (FormatException fex)
{
...CODE to catch the exception
}
The code works but when the first exception occours, I observe a massive delay of two seconds or more. I guess that is the time when the DLL for the Exception is loaded. Once that has happened, there is no observable delay.
I observed the same for example when using data components (e.g. DataGrid) for displaying data. The first loading takes much longer than the consecutive ones.
Is there a way to load the according DLLs when the application starts ?
Thanks
ch
|
|
|
|
|
You can see if assembly loading is eating up your time by looking at the ".NET CLR Loading" performance object in performance monitor. This will tell you how many assemblies are loading and when. Make sure you look at your application process rather then the _total instance because it can be misleading. It is also a good idea to look at memory, exceptions and jiting in this case to see what is going on.
If the problem really is loading exceptions, which anything thrown by int.parse should be already loaded, then you should look into using ngen on your application to reduce startup time.
I can imagine the sinking feeling one would have after ordering my book,
only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
|
|
|
|
|
I have the same problem here, but only while running under the VS.NET debugger. When running standalone, the exception is very fast.
|
|
|
|
|
Hi there,
I solved the problem now. Actually, the problem is that the code is translated into machine language in time. So, when first time executed, it takes a lot longer than subsequent calls. But, with the ngen.exe deployed with VS you can create a native image of your code and place it in the assembly cache, so that even the first execution is as fast as all the others.
regards
ch
|
|
|
|
|
I wanna ask easier way for an T-SQL Clause
Imagine a table AS following
CODE - TYPE - TOTAL<br />
1132 IN 100<br />
1134 IN 140<br />
1134 OUT 230<br />
1135 IN 240<br />
1135 OUT 50<br />
1136 IN 70<br />
1137 OUT 110
I need a sqlclause it will group by code and calculate Total, u have to multply OUT type with -1
the final table what i need to get is
CODE - TOTAL<br />
1132 100<br />
1134 -90<br />
1135 190<br />
1136 70<br />
1137 -110
I assume The clause like that
select CODE,SUM(If (TYPE='OUT',TOTAL*-1, TOTAL) from DETAILS<br />
group by CODE,TYPE Order by CODE
But something is missing
-- modified at 9:24 Monday 5th September, 2005
|
|
|
|
|
I think this is what you want.
select CODE, SUM(CASE WHEN (TYPE = 'OUT') THEN TOTAL*-1 ELSE TOTAL END )
from DETAILS
group by CODE
Order by CODE
I can imagine the sinking feeling one would have after ordering my book,
only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
|
|
|
|
|
I please need to know how to round and format numbers in C#. For example how to round a number to 3 decimal places, and to format it with commas in, and to add the Rand sign, etc.
Regards,
Brendan
|
|
|
|
|
Look at the Math.Round(double, digits) method, the Double.ToString(format) method, and the String.Format(format, ...) method.
Examples:
double n = 3.1415926536;
double d = Math.Round(n, 3);
string s = n.ToString("0.###");
string s = n.ToString("c2", new CultureInfo(1053))
int i = 42;
string s = String.Format("Code: {0:00000}.", i);
---
b { font-weight: normal; }
|
|
|
|
|
Hi
Please help me in Overlapping the images
I have taken two images in two pictureboxes, the images (.bmp) type Polygon shapes. If i place one image on another the backgroud image is not displaying. how can i see the two images at the same time.
dhanunjay
|
|
|
|
|
I took an image in the piture box. i hav written the code for rotation using the Matrix. It is rotating. but if i stretch the image, image is not streching only picture box is stretching.Please help me to resize the image
|
|
|
|
|
Hello!
You can use the Property "SizeMode" in the PictureBox Class.
But you have to use the "Image" Property, not the "BackgroundImage".
_picturebox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
Good luck!
Martin
|
|
|
|
|
Hi,
how load to picturebox TIFF image with included color schema?
Greetings
|
|
|
|
|
Hi, I have the situation where I need to create a wrapper for an unmanaged dll. My only problem is that all examples are shown with the dll specified before hand. I would like to specify the dll to use at runtime. If this is possible, please let me know. My reason for this is I have about 10 dll's which are would all have the same signatures, but are designed to access differenct machines.
So basically if I am not able to pass in the dll to use when needed, I am going to be stuck having 10 different classes all to do a similar thing. Thanks
|
|
|
|
|
Hi, just to add a bit more to this, the following code would work fine, except that I have to mark dllLocation as const. If I change it, it does not work, and this is exactly what I need. So any help would be appreciated.
const string dllLocation = "test.dll";
[DllImportAttribute(dllLocation)]
public static extern void SetServerName (string pServerName);
|
|
|
|
|
Hi!
At least the name of the DLL has to be constant, if you use this approach.
If the path of the dll is unknown at compile time, then you can still change the current directory to the DLL's path at runtime and then use the DLL function, this will work.
Regards,
mav
|
|
|
|
|
Hi, its never known at runtime what the path will be. You mentioned though 'using this approach'. Could you let me know some other approaches I could use if this one does not help me?
|
|
|
|
|
If everything else fails you can P/invoke LoadLibrary and then try to call the functions in the DLL somehow. I think I saw an article here somewhere doing just this, but I could be wrong.
Good luck,
mav
|
|
|
|
|
I don't think it's possible to do it dynamically using .NET.
What you could do is make an unmanaged DLL that works as a stub, which is always the same. Then you link to that stub DLL from your .NET code. That DLL determines the path of the DLL to load, and uses LoadLibrary and GetProcAddress to link to it.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
The amount of sleep the average person needs is five more minutes. -- Vikram A Punathambekar, Aug. 11, 2005
|
|
|
|
|
I have an array declared like this:
byte[,] grayPixels = new byte[rows, cols];
later in the code, (where I don't have access to rows or cols ), I have to iterate through grayPixels , I am using the following code to find the number of rows
int nRows = grayPixels.Length;
How can I find out the number of columns in the above array? Thanks in advance...
- A programmer's national anthem; "AAAAAHHHHH!!!!"
|
|
|
|
|
Use grayPixels.GetLength(0) to get the size of the first dimension, and grayPixels.GetLength(1) to get the size of the second dimension.
---
b { font-weight: normal; }
|
|
|
|
|
Hello
int nRows = grayPixels.GetLength(0);
int nCols = grayPixels.GetLength(1);
Andrew
|
|
|
|
|
Thank you very much...
- A programmer's national anthem; "AAAAAHHHHH!!!!"
|
|
|
|
|
Problems:
(1) How to get dynamic “Crystal Report” data I mean I have 3 tables named as Job, JobDesc and Emp_Info’ there is a primary key name JobNo now I want that I pass sqldb command at run time and in where clause I pass the JobNo so then on the crystal report only data show which have given JobNo.
(2) How to set Multi-line Report in Crystal Report Detail Section. Like this:
(3) How to display custom date format (Sep-06-2005) in Crystal Report.
Job No Title Employee Id
_____________________________________________________
1 Dummy Dummy Title Dummy Title 001
2 Dummy Title Dummy Title Dummy 002
sdfshdkfsdhkfshdkhs
3 Dummy Title Dummy Title Title 003
_______________________________________________________
I mean which property I have to change in order to get this kind of look.
Sample code can be fine at:
http://sktech.freewebspace.com/My%20Problems/[^]
Yours sincerely,
|Muhamad Waqas Butt|
waqasb4all@yahoo.com
www.sktech.freewebspace.com
-- modified at 4:30 Monday 5th September, 2005
|
|
|
|
|
I have a Multi Line Textbox. User will input address information.I wantta set cursor to new line, when user press enter key. I try following code to achive but it always set cursor to first line. what do u offer me :S
protected sub txtAddress_KeyUp(........) handles txtaddress.keyup
if (e.key= keys.enter){
txtaddress.text &= envoirenment.newline;
}
end sub
|
|
|
|