|
Yes Right.. Try that.
|
|
|
|
|
Hello,
does anyone know how I can create buttons in the screen preview in C#?
With screen preview I mean the little screen you see when your pointer is on the program in the taskbar. Any idea's? Windows Media Player uses it, so it is possible.
|
|
|
|
|
|
Thank you very much!
|
|
|
|
|
I can't seem to find help on this anywhere, but is there a way to detect the user's preference to show mnemonics? This is an 'Ease of Access Center' setting in vista and 7, and an Display->Appearance 'Effect' in XP.
Maybe WMI? Any help would be appreciated. My component vendor has a on/off toggle to display, but I'd rather have it default to whatever the system setting is.
|
|
|
|
|
It seems that System.Drawing.Font won't recognize built in printer fonts, so the font gets substituted. This is not just a cosmetic problem for me, it's a show stopper. I'm trying to print bar codes using the printer's built in fonts.
Does anybody know a workaround?
[edit]I saw the font class has a static method called FromHfont(). Maybe I can use it with some P/Invoke magic...[/edit]
[edit]Nope. When I create the font from a HFONT, Font.FromHfont() throws a "The font is not a true-type font" exception. I suppose I'll just have to solve this using C++/CLI...[/edit]
--
Kein Mitleid Für Die Mehrheit
modified on Tuesday, October 27, 2009 2:59 PM
|
|
|
|
|
Hi,
First of all I don't know the answer, but I am interested to learn about this.
Do other apps use your printer fonts the way you want it? Did your printer come with fonts you could install on your PC?
Jörgen Sigvardsson wrote: I suppose I'll just have to solve this using C++/CLI...
I don't see how the language would be a factor.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Luc Pattyn wrote: Do other apps use your printer fonts the way you want it? Did your printer come with fonts you could install on your PC?
The fonts are built into the printer. In this particular case, they're barcode fonts. The reason for this is two fold:
1) You don't have to perform checksum calculations yourself - just draw your string with the printer font and you'll get a barcode
2) They don't want to release the fonts because of intellectual properties. You usually have to buy these fonts.
The fonts are locked in the memory of the printer, and cannot be installed on the computer.
Luc Pattyn wrote: I don't see how the language would be a factor.
I feel more comfortable using the Win32 API using C++ than I do C#. Feels more natural I guess. :shrug:
--
Kein Mitleid Für Die Mehrheit
|
|
|
|
|
These types of printers generally have their own API provided by the maker of the printer. Some offer ActiveX (and if you're lucky .NET) components that are often free, by request, or if they are jerks, they'll charge for it (like Wasp Labelers).
Check w/ the manufacturer of the printer.
|
|
|
|
|
It's a perfectly GDI-capable printer. I've done this before in C++, so I know it's possible. Heck, you can even use Wordpad to print your labels.
--
Kein Mitleid Für Die Mehrheit
|
|
|
|
|
Jörgen Sigvardsson wrote: you can even use Wordpad to print your labels
Doesn't that imply the printer fonts are also installed on Windows, and you tell Notepad to chose such font? If so, they must appear in FontCollection.Families with their correct names, and you could use them in yout C# app?
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
You tell Wordpad what printer it should use. Then it'll list all the installed fonts, and the fonts available in the printer.
The Winforms stuff only handles True/Open-type fonts. You get a clear indication of that when you create a GDI font object and pass it to Font.FromHfont(). The exception explicitly says "Only true types are supported", meaning that I can never reference printer fonts using System.Drawing.Font. I'm guessing it's a GDI+ limitation, due to the fact that the printer fonts are bitmapped fonts, and not true-type ones.
From what I can tell, the only way to use these fonts is to go the GDI32 way...
--
Kein Mitleid Für Die Mehrheit
|
|
|
|
|
OK, I think I understand what you are saying. I don't like it much, OTOH what could GDI+ do with a font that only exists in a printer, it can't use it to draw on the screen...
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
GDI manages it by substituting the font with something it can render. You wouldn't expect to draw with it on screen anyhow. Oh well. I'm already doing it the Win32 way as we speak...
--
Kein Mitleid Für Die Mehrheit
|
|
|
|
|
I have a problem that is very similar to others that I have seen around the web but no exactly the same. I am trying to call a DLL written in unmanaged C++, from an application written in C#. The C# application will need to pass the DLL function two structs, one with input variables and one for the return variables. I have tried some of the similar solutions but still have not been successful. I have some experience with C# but I am very new to calling DLLs. Any help would be greatly appreciated. Here is my code:
C++:
extern "C"
{
typedef struct
{
unsigned int iSignalCount;
double *dSignal;
unsigned int iFilterCount;
double *dFilter;
} My_Function_Input_Type;
typedef struct
{
unsigned int iDftCount;
double *dDft;
double *dFilteredSignal;
} My_Function_Return_Type;
_declspec(dllexport) void FFT_Convolution(My_Function_Input_Type input, My_Function_Return_Type output);
}
modified on Thursday, October 29, 2009 1:43 PM
|
|
|
|
|
Hi,
you need P/Invoke, which isn't very simple. And having array pointers inside structs makes it even harder.
is the C++ code yours, can you (temporarily) modify it?
I assume the input arrays are instantiated and loaded by managed code, and the arrays in the result are created and loaded by native code? please confirm.
show us what you have so far, and give clear symptoms. I'm not going to explain it all, I'll build on what you have.
And how will the result arrays ever get freed? (it would be much easier if they too could start as managed arrays, hence really be part of the input).
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Thank you for replying...
The C++ code is not mine. All of the array instantiations is done on the C# side.
Here is my C# code:
[StructLayout(LayoutKind.Sequential)]
public struct My_Function_Input_Type
{
public UInt32 iSignalCount;
public Double[] dSignal;
public UInt32 iFilterCount;
public Double[] dFilter;
}
[StructLayout(LayoutKind.Sequential)]
public struct My_Function_Return_Type
{
public UInt32 iDftCount;
public Double[] dDft;
public Double[] dFilteredSignal;
}
[DllImport(@"My_DLL.dll")]
public static extern void My_Funtion(My_Function_Input_Type input, ref My_Function_Return_Type rtrn);
Main()
{
My_Function_Input_Type input = new My_Function_Input_Type();
input.dSignal = ReadFile(Raw_TextBox.Text);
input.iSignalCount = Convert.ToUInt32(input.dSignal.Count());
input.dFilterKernel = ReadFile(Filter_TextBox.Text);
input.iFilterCount = Convert.ToUInt32(input.dFilterKernel.Count());
My_Function_Return_Type rtrn = new My_Function_Return_Type();
rtrn.iDftCount = PowerOfTwo(Convert.ToUInt32(input.dSignal.Count()));
rtrn.dDft = new double[Convert.ToInt32(rtrn.iDftCount)];
rtrn.dFilteredSignal = new double[Convert.ToInt32(rtrn.iDftCount)];
My_Function(input, ref rtrn);
DoSomethingWithOutput(rtrn);
}
This gives me a "Exception of type 'System.ExecutionEngineException' was thrown." error.
Thank you in advance for any guidance you can provide.
|
|
|
|
|
Hi,
CircuitDoc wrote: All of the array instantiations is done on the C# side
that is nice.
I now have several comments:
1. I never had a ExecutionEngineException before. Most often a P/Invoke mistake yields an access violation of some kind.
2. I am not familiar with Array.Count() method; I would use Array.Length. And I would expect Count() to return an integer, so I don't see a need for Convert.ToUInt32() four times.
3. Your second parameter has ref although nothing in the C++ source justifies that. I would throw it out (twice).
4. In C/C++ a double* is a simple pointer to one or several doubles; in C# double[] is the reference to an array, that is not the same as a data pointer. You need to:
- replace all arrays by IntPtr types inside the structs;
- allocate the arrays outside the structs;
- pin or fix each of the arrays so they can't be moved around while native code is running; this takes either the fixed keyword and the unsafe keyword and compiler switch, or, my preference, the GCHandle class. An C# example follows:
public int ArrayHandle() {
int dim=10000;
int[] numbers=new int[dim];
...
GCHandle handle=GCHandle.Alloc(numbers, GCHandleType.Pinned);
int sum=SumArray(handle.AddrOfPinnedObject(), dim);
handle.Free();
return sum;
}
That should get you going. If and when it still fails, please show updated code and symptoms again.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
modified on Tuesday, October 27, 2009 4:02 PM
|
|
|
|
|
Thanks to Luc Pattyn and a little more reasearch on the Web, I solved this using the GCHandle Class.
Here is the updated working code:
public struct MY_Input_Type
{
public UInt32 iSignalCount;
public IntPtr dSignal;
public UInt32 iFilterCount;
public IntPtr dFilterKernel;
}
public struct MY_Return_Type
{
public UInt32 iDftCount;
public IntPtr dDft;
public IntPtr dFilteredSignal;
}
[DllImport(@"MY_DLL.dll")]
public static extern uint PowerOfTwo(uint b);
[DllImport(@"MY_DLL.dll")]
public static extern void FFT_Convolution(MY_Input_Type input, MY_Return_Type rtrn);
public void Start(string rawFile, string filterFile, string outFile)
{
MY_Input_Type input;
MY_Return_Type rtrn;
double[] filterData;
double[] rawData;
double[] returnData;
double[] returnFilter;
filterData = ReadFile(rawFile);
rawData = ReadFile(filterFile);
GCHandle rawHandle = GCHandle.Alloc(rawData, GCHandleType.Pinned);
GCHandle filterHandle = GCHandle.Alloc(filterData, GCHandleType.Pinned);
input.dSignal = rawHandle.AddrOfPinnedObject();
input.dFilterKernel = filterHandle.AddrOfPinnedObject();
input.iFilterCount = Convert.ToUInt32(filterData.Length);
input.iSignalCount = Convert.ToUInt32(rawData.Length);
rtrn.iDftCount = PowerOfTwo(Convert.ToUInt32(rawData.Length));
returnData = new double[Convert.ToInt32(rtrn.iDftCount)];
returnFilter = new double[Convert.ToInt32(rtrn.iDftCount)];
GCHandle rtrnData = GCHandle.Alloc(returnData, GCHandleType.Pinned);
GCHandle rtrnFilter = GCHandle.Alloc(returnFilter, GCHandleType.Pinned);
rtrn.dDft = rtrnData.AddrOfPinnedObject();
rtrn.dFilteredSignal = rtrnFilter.AddrOfPinnedObject();
FFT_Convolution(input, rtrn);
WriteOutput(returnFilter, returnData, outFile);
rawHandle.Free();
filterHandle.Free();
rtrnData.Free();
rtrnFilter.Free();
}
If anyone sees a way to optimize this code, please let me know. Thanks...
|
|
|
|
|
Hi have a good day
<br />
string mysrt = "Hello {0}";<br />
<br />
Console.WriteLine ("Hello {0}" , "World");<br />
How I can do the above Code With MessageBox.Show ??
thank in advance
P.S:
I don't want to use The String.Replace
I know nothing , I know nothing ...
|
|
|
|
|
Stark DaFixzer wrote: I don't want to use The String.Replace
I don't want to copy the documentation.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Succinct and sarcastic. I like it!
CCC solved so far: 2 (including a Hard One!)
|
|
|
|
|
Console.WriteLine uses String.Format behind the scenes. Pass the normal parameters to String.Format, and show the return value using MessageBox.Show
|
|
|
|
|
Stark DaFixzer wrote: I don't want to use The String.Replace
Why? This is exactly what Console.Writline does.
CCC solved so far: 2 (including a Hard One!)
|
|
|
|
|
use like this ...
MessageBox.Show(String.Format(mystr , "world"));
|
|
|
|