|
dll generated by vc++
__declspec(dllexport) long __stdcall LPRLoadImage( const char* pFilePath, LPRImage** ppImage );
and LPRImage is a struct,defind as
struct LPRImage
{
int nSize;
int nChannels;
int depth;
int nColorMode;
int dataOrder;
int origin;
int width;
int height;
int imageSize;
unsigned char *pData;
int step; SYSTEMTIME timeStamp;
};
how can i call LPRLoadImage in c#,help me!!!!
|
|
|
|
|
You need to declare a function prototype and decorate it using the DllImportAttribute class. You also need to declare a struct corresponding to LPRImage and decorate it with the StructLayoutKindAttribute class using LayoutKind.Sequential . Make sure your struct elements are the same size (in bytes) as the C++ data types. You should be able to use the same types for everything except SYSTEMTIME and unsigned char *.
This link[^] is a good place to start finding the information you need. You'll especially need to know about this[^] and this[^].
|
|
|
|
|
autually ,i had declare the prototype as below:
[StructLayout(LayoutKind.Sequential)]
public struct LPRImage
{
public int size;
public int nChannels;
public int depth; public int nColorMode;
public int dataOrder;
public int origin;
public int width;
public int height;
public int imageSize;
[MarshalAs(UnmanagedType.ByValArray)]
public byte[] pData;
public int step;
public SYSTEMTIME timeStamp;
}
public static extern int LPRLoadImage([System.Runtime.InteropServices.InAttribute()] [MarshalAsAttribute(UnmanagedType.LPStr)] string pFilePath, ref System.IntPtr ppImage);
but i don't know how to call the LPRLoadImage function,because ppImage is a pointer,i call like below:
LPRStructure.LPRImage Image = new LPRStructure.LPRImage();
IntPtr pImge = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(LPRStructure.LPRImage)));
Marshal.StructureToPtr(Image, pImge, false);
int i = LPRRender.LPRLoadImage(s, ref pImge);
when i run this,the return value i = -2 [-2 :invalid parameter ]
i think the ppImage is a pointer which point to the pointer of struct,how can i transfer the ppImage parameter to the function?
|
|
|
|
|
I think the call to StructureToPtr is causing the problem. Your code should look similar to the listing below (which I haven't tested):
IntPtr pImge = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(LPRStructure.LPRImage)));
int i = LPRRender.LPRLoadImage(s, ref pImge);
LPRStructure.LPRImage Image = (LPRStructure.LPRImage)Marshal.PtrToStructure(pImge, typeof(LPRStructure.LPRImage));
modified on Thursday, January 14, 2010 8:59 AM
|
|
|
|
|
thanks for u replay,but i test it,the LPRLoadImage return value is also -2 ,i don't know how to understand the LPRImage** ppImage in c++
|
|
|
|
|
You can call Win32 DLLs in C# with P/Invoke:
http://msdn.microsoft.com/en-us/magazine/cc164123.aspx
April
Comm100 - Leading Live Chat Software Provider
modified 27-May-14 8:59am.
|
|
|
|
|
Hi,
I use the following code to open a folder1 with window explorer and with file1 inside select. But the problem is that if the desktop has a file with the same filename as file1, it will select the desktop file instead of selecting the right file1 in the folder1 ! Why ?
Process p = new Process();
p.StartInfo.Filename = file1;
p.StartInfo.WorkingDirectory = folder1Path;
p.StartInfo.Arguments = "/Select," + file1;
p.Start();
Thanks
|
|
|
|
|
Hi,
I think you were quite lucky that your arguments actually started Explorer.
Review this http://support.microsoft.com/kb/307856/en-us[^]
I would have tried this (not tested):
Process p = new Process();
p.StartInfo.Filename = "explorer.exe"
p.StartInfo.Arguments = String.Format("\"{0}\" /select,\"{1}\"", folder1Path, file1);
p.Start();
where folder1Path and file1 are both fully qualified.
Alan.
|
|
|
|
|
I think you can use FindWindowEx to get the SysListView32 of Windows Explorer, then use SendMessage with LVM_SETITEMSTATE to select the items. The difficulty is to know the position of the items. Perhaps LVM_FINDITEM can be used for this. In this way you can also select multiple files.
modified 27-May-14 4:57am.
|
|
|
|
|
Dear developers,
I am coding a very small project for my study. I want to refresh form1 after form2 is closed. For example, I open form1 and click one button to open form2 and in form2 I can insert data to the database (ex : tblItem). In addition, combobox in form1 retrieves data from the database (tblItem) too. So, after inserting data from form2 and when I close the form2, I want the comboxbox in form1 refresh to retrieve the last update of tblItem data.
Here is my code to open form2
form2 frmitem = new form2();
frmitem.ShowDialog();
Please advise, thanks.
Visoth
Chuon Visoth
Angkor Wat - Cambodia
asp.net - c sharp beginner
|
|
|
|
|
You can paste your code directly behind the ShowDialog() row. If you call the ShowDialog() function, the main form will "sleep" until the dialog window is closed.
For example, if you call ShowDialog(), and on the next line you call Messagebox.Show(), the messagebox will be shown as soon as the dialog window is closed.
So your code might look like this:
form2 frmitem = new form2();
frmitem.ShowDialog();
UpdateMyComboBox();
|
|
|
|
|
Sorry, can give explain me more detail than this?
Chuon Visoth
Angkor Wat - Cambodia
asp.net - c sharp beginner
|
|
|
|
|
It's not possible to explain it in more detail, because it's just too simple... Maybe my explanation was not clear enough, I'll try once more.
You asked how to refresh a combobox after a child form has closed.
The answer is simple - the code that refreshes the combobox should be right behind the form.ShowDialog() line. It will be executed as soon as the child form is closed, and that's what you want.
|
|
|
|
|
private void lkl_additem_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) //form1
{
//Open form2 from form1
form2 frmitem = new form2();
frmitem.ShowDialog();
this.cbo_itemname.Refresh(); // This is a combobox in form1 which I wanna update when form2 closes.
}
Is the code like this??? However, it doesn't work.
Chuon Visoth
Angkor Wat - Cambodia
asp.net - c sharp beginner
|
|
|
|
|
Hi,
Actually he wants you to place the code that refreshes the combobox just before the following line in ur code..
frmitem.ShowDialog();
Hope u understand....
Regards,
Tash
|
|
|
|
|
Thnx a ton. Ur solution is the best
|
|
|
|
|
What is the equivalent window style for FormBorderStyle.Fixed3D, FormBorderStyle.FixedSingle, FormBorderStyle.FixedDialog, FormBorderStyle.SizableToolWindow and FormBorderStyle.FixedToolWindow? The only one I know is WS_THICKFRAME for FormBorderStyle.Sizable.
|
|
|
|
|
So I'm trying to display an icon in a PictureBox control while preserving the alpha of the icon image. Loading the icon and applying it to the control looks something like this:
Icon icon = new Icon("thisIsTheIcon.ico");
pboAppIcon.BackgroundImage = icon.ToBitmap();
This works fine except that all transparent areas of the icon are show as black. I tried to get around this using the Bitmap class' .MakeTransparent method, but the result looks terrible, since the icon uses varying alpha translucency (near-black artifacts remain).
Normally I'd just let this go as a .Net eccentricity, except that I've seen another application achieve exactly what I'm after using identical code and icons. I'm wondering if there's a Form style or a flag somewhere that needs to be changed.
Does anyone have any suggestions?
|
|
|
|
|
You have to load the file as Bitmap, not Icon.
Bitmap bmp = (Bitmap)Image.FromFile("thisIsTheIcon.ico");
pboAppIcon.BackgroundImage = bmp;
|
|
|
|
|
I have an array of bytes. I need to remove the first 16 bytes of the array, then append another byte array onto it. What do you suggest is the best way to do this?
|
|
|
|
|
Hi,
for small arrays, just do it; i.e. allocate a new array of correct length, and copy the data you want in it (see Array.Copy).
for large arrays (hundreds of MB), don't do it; make sure you don't need it, i.e. either make your consumer smart enough to skip some, and combine two arrays, or teach your producer(s) to first disclose lengths so you can allocate the final array at once, then let the producer(s) fill their allotted space.
FYI: most .NET methods that take an array also have an overload that takes (array, startindex, length) in an attempt to alleviate such problems.
|
|
|
|
|
I addition to Luc's advice, have a look at the System.Buffer[^] class, specifically it's BlockCopy[^] method.
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
I rarely use Arrays in a situation like this. I prefer using the generic List[^] class. Using a list for your application would look like this:
Using System.Collections.Generic;
[...].
List<Byte>myList = new List<Byte>();
myList.AddRange(someByteArray);
myList.RemoveRange(0,16);
myList.AddRange(someOtherByteArray);
Byte[] retVal = myList.ToArray();
return retVal;
|
|
|
|
|
If you really must use an array, then the others have already given you perfectly reasonable options. However, you could also create a new data structure that is like a list but that you can remove items from both sides without a speed penalty.
A list works by internally storing an array and removing/adding elements near the end of the array as needed. If you remove items from the beginning of a list, all the rest of the items will have to be shifted to the beginning to get rid of those empty elements. However, your class (DoubleSidedList?) could just keep the values near the center of the array. That way, you could trim or add to either side without worrying about speed problems when expanding or contracting either side of the collection.
Naturally, this would incur a small performance penalty due to wrapping an array in a collection type.
|
|
|
|
|
If the size is very large and performance is very important, I suggest you create a new data structure:
class ExArray{
byte[] data;
int start;
int end;
public this[int i]
{
get { return data[(start + i) % data.Length]; }
set { data[(start + i) % data.Length = value; }
}
public Length { get { return end - start >= 0 ? end - start : end - start + data.Length; }}
public void Shift(...){...}
public void Slice(...){...}
}
April
Comm100 - Leading Live Chat Software Provider
modified 27-May-14 8:58am.
|
|
|
|