|
Hello, i use code from p/invoke to enumerate resources in a programme ( a little like resourcehacker does that ).
When the resource has a type with a name, my code display an error. It's ok for an ID. I place here a piece of result:
Type : MUI
Name: 1
erreur: -532462766
Type : 3
Name: 1
Language: 1033.
why in my source EnumResourceLanguages return false for resource type identified by Name ?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.ComponentModel;
namespace test2Enumressource
{
class Program
{
private const uint LOAD_LIBRARY_AS_DATAFILE = 0x00000002;
[DllImport("kernel32.dll", SetLastError = true)]
private static extern IntPtr LoadLibraryEx(
string lpFileName,
IntPtr hFile,
uint dwFlags);
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool FreeLibrary(IntPtr hModule);
#region équivalent des macros
private static bool IS_INTRESOURCE(IntPtr value)
{
if (((uint)value) > ushort.MaxValue)
return false;
return true;
}
private static uint GET_RESOURCE_ID(IntPtr value)
{
if (IS_INTRESOURCE(value) == true)
return (uint)value;
throw new System.NotSupportedException("value is not an ID!");
}
private static string GET_RESOURCE_NAME(IntPtr value)
{
if (IS_INTRESOURCE(value) == true)
return value.ToString();
return Marshal.PtrToStringUni((IntPtr)value);
}
#endregion équivalent des macros
#region Enumération des langues des ressources
[DllImport("kernel32.dll")]
static extern bool EnumResourceLanguages(IntPtr hModule, IntPtr lpszType,
IntPtr lpName, EnumResLangDelegate lpEnumFunc, IntPtr lParam);
private delegate bool EnumResLangDelegate(
IntPtr hModule,
IntPtr lpszType,
IntPtr lpszName,
ushort wIDLanguage,
IntPtr lParam);
private static bool EnumResLangCallback(
IntPtr hModule,
IntPtr lpszType,
IntPtr lpszName,
ushort wIDLanguage,
IntPtr lParam)
{
Console.WriteLine("\t\tLanguage: {0}", wIDLanguage);
return true;
}
#endregion Enumération des langues des ressources
#region Enumération des noms des ressources
[DllImport("kernel32.dll",
CharSet = CharSet.Unicode, SetLastError = true)]
static extern bool EnumResourceNames(
IntPtr hModule,
IntPtr lpszType,
EnumResNameDelegate lpEnumFunc,
IntPtr lParam);
private delegate bool EnumResNameDelegate(
IntPtr hModule,
IntPtr lpszType,
IntPtr lpszName,
IntPtr lParam);
static bool EnumRes(
IntPtr hModule,
IntPtr lpszType,
IntPtr lpszName,
IntPtr lParam)
{
Console.WriteLine("\tName: {0}", GET_RESOURCE_NAME(lpszName));
bool bret = EnumResourceLanguages(hModule, lpszType,
lpszName, new EnumResLangDelegate(EnumResLangCallback), lParam);
if (bret == false)
{
throw new Win32Exception(Marshal.GetLastWin32Error());
}
return true;
}
#endregion Enumération des noms des ressources
#region Enumération des types des ressources
private delegate bool d_EnumResourceTypes(
IntPtr hModule,
IntPtr lpszType,
long lParam);
[DllImport("kernel32", CharSet = CharSet.Unicode, SetLastError = true)]
private extern static long EnumResourceTypes(IntPtr hModule, d_EnumResourceTypes callback, long lParam);
static bool EnumResourceTypesCallback(IntPtr hModule, IntPtr lpszType, long lParam)
{
if (IS_INTRESOURCE(lpszType))
{
Console.WriteLine("Type : {0}", GET_RESOURCE_ID(lpszType));
}
else
{
Console.WriteLine("Type : {0}", GET_RESOURCE_NAME(lpszType));
}
if (EnumResourceNames(hModule,lpszType,
new EnumResNameDelegate(EnumRes), IntPtr.Zero) == false)
{
Console.WriteLine("erreur: {0}", Marshal.GetLastWin32Error());
}
return true;
}
#endregion Enumération des types des ressources
[STAThread]
static void Main(string[] args)
{
string file = @"C:\windows\system32\notepad.exe";
if (args.Length == 1){
file = args[0];
}
IntPtr hMod = LoadLibraryEx(file, IntPtr.Zero, LOAD_LIBRARY_AS_DATAFILE);
long lParam = 0;
EnumResourceTypes(hMod, new d_EnumResourceTypes(EnumResourceTypesCallback), lParam);
FreeLibrary(hMod);
}
}
}
|
|
|
|
|
I only a wrong signature
[DllImport("kernel32.dll",
CharSet = CharSet.Unicode, SetLastError = true)]
static extern bool EnumResourceLanguages(IntPtr hModule, IntPtr lpszType,
IntPtr lpName, EnumResLangDelegate lpEnumFunc, IntPtr lParam);
and the result is ok :
Type : EDPPERMISSIVEAPPINFOID
Name: MICROSOFTEDPPERMISSIVEAPPINFO
Language: 1033
Type : MUI
Name: 1
Language: 1036
Language: 1033
|
|
|
|
|
Hi,
I need to draw 2 lines in a picturebox using mouse. both line origin should be same and after completing the line need to measure the angle between 2 lines automatically.
Please help me to complete the code
|
|
|
|
|
What code? You haven't actually posted any. Or were you expecting us to write it for you? You need to set expectations up front.
This space for rent
|
|
|
|
|
First write the code to draw the lines. There's many, many examples of that available all over the net. (Use Google if you need.)
Then, notice that you have the coordinates of the 3 points, vertex, line 1 end, line 2 end.
You can calculate the angle from that using basic trigonometry.
Ready... begin!
"Fairy tales do not tell children the dragons exist. Children already know that dragons exist. Fairy tales tell children the dragons can be killed."
- G.K. Chesterton
|
|
|
|
|
No - we don't do your homework for you!
But... some hints.
I you don't need a picture box: use a Panel instead.
Handle the Mouseclick event for the Panel, and capture three clicks:
Origin (x, y)
p1 (x1, y1)
p2 (x2, y2) The click Location is provided in the MouseEventArgs and are relative to the Panel.
Invalidate the Panel for each click.
Handle the Paint event for the panel.
Draw a circle at each point (if provided) using Graphics.DrawEllipse and the lines as points become available using Graphics.DrawLine
Once you have the three points, you can calculate the angle with simple trig.
Wolfram MathWorld[^] can give you the equation if you search it for "Line-Line Angle"
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Hi,
have anyone have the same problem:
In table i have blob field. On windows application would like to fill textbox with content from field (blob).
How can I do this with databinding, no with sql statements:
this.tST_DESCTextBox.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.tSTBindingSource, "TST_DESC";, true));
|
|
|
|
|
How do you bind blob to textbox ? what u have saved in blob ? you can save any type of files in database as IMAGE, I don't know how you show it in textbox
Find More .Net development tips at : .NET Tips
The only reason people get lost in thought is because it's unfamiliar territory.
|
|
|
|
|
teddddddddddd wrote: How can I do this with databinding, no with sql statements AFAIK, the databinding controls generate SQL. It would be hard to speak to a database-connection without it.
Why the requirement? It's not that hard to get a reader to return the blob.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
BLOB stands for Binary Large Object, I believe. The short of it is, you have to know the object type, often a file of some sort. If it is a file, you need to know it's original file extension. When you retrieve the BLOB from the database what you are getting are the individual bytes from the file. You will get a large array holding the bytes. Once you have the bytes you can write them to disk in a file with the proper extension, and presto you have the original file.
Here's a Microsoft article for just such.
https://support.microsoft.com/en-us/kb/317016[^]
You don't actually need to write the file to disk, you can store it in memory for binding purposes.
Regards
|
|
|
|
|
Hi Guys,
I am stuck in some problems regarding the uses of APIs.
my task is to upload single/Bulk product over Ebay and Amazon using their APIs, I got lots of APIs as well but I didn't the accurate way to implement that thing if anyone have any GUI kind of sample or having any idea how to accomplish desire task, then let me know.
and if anything that you don't understand properly than also let me know.
Thanks in advance
|
|
|
|
|
|
Suppose I have 2 objects like the following
public class Toy
{
public int ID{get;set;}
public double Price{get;set;}
public sting Color{get; set;}
}
public class Merchandise
{
public List<Toy> toyList;
public Merchandise()
{
toyList= new List<Toys>();
toyList.Add(new Toy {ID = 1, Price = 10, Color = "Red"});
toyList.Add(new Toy {ID = 2, Price = 10, Color = "White"});
toyList.Add(new Toy {ID = 3, Price = 10, Color = "Black"});
}
public string this[int toyId, string toyProperty]
{
get{return listOfProducts.FirstOrDefault(prod => prod.Id == productId);}
set{listOfProducts.FirstOrDefault(prod => prod.Id == productId).toyProperty = value;}
}
}
I want to be able to dynamically choose which property to insert into my LINQ query inside of the Indexer's set property. That way I can set the Price or Color of the Toy object dynamically.
I created the toyProperty parameter in the Indexer parameter list so that the code that will consume the Indexer will be able to pass a value to the toyProperty in the LINQ Query.
The code consuming the Indexer will look something like the following
public double price = txtPrice.Text;
public string color = txtColor.Text;
public Merchandise item = new Merchandise();
item[2, "Price"].Price = price;
item[2, "Color"].Color = color;
My Lambda Expression inside the set property of the Indexer does not work of course but I wonder if it is missing something that could help to make it work.
modified 17-May-16 16:16pm.
|
|
|
|
|
While there would be a way to do something close to what you want (which I wouldn't recommend), I don't think you've thought this through:
The indexer-getter "attempts" to return a Toy but you declared the type of the indexer as string . Maybe you intended to dynamically access the given toyProperty there as well and return it formatted as a string ? Your usage-example actually employs the getter, not the setter, because you (statically) access a property before the assignment.
Apart from that, you're planning on conceding syntax correctness and type safety here. Why? If you tell us your ultimate goal here - why you think you need this - we will probably be able to provide you with ideas for better solutions.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Thanks for your reply. In my test project my code does return a Toy object. It looks something like this
<pre lang="c#">
public Toy this[int toyId, string toyProperty]
{
get{return listOfProducts.FirstOrDefault(prod => prod.Id == productId);}
set{listOfProducts.FirstOrDefault(prod => prod.Id == productId).toyProperty = value;}
}
This is just a test project to find out how I can use a single set property to change different properties using one LINQ Query. Also you are correct my syntax should have been
item[2, "Price"] = price;
item[2, "Color"] = color;
modified 17-May-16 17:01pm.
|
|
|
|
|
MadDashCoder wrote: In my test project my code does return a Toy object. Then the value in the setter would also be of type Toy . The only half sensible types to use would be object or string .
MadDashCoder wrote: This is just a test project to find out how I can use a single set property to change different properties using one LINQ Query. It's always going to be messy and I would avoid it unless there's some very compelling reason to do so.
Staying with your pseudo-code-style, it should look like this:
public object this[int toyId, string toyProperty]
{
get { return listOfProducts.Single(prod => prod.Id == toyId).toyProperty; }
set { listOfProducts.Single(prod => prod.Id == toyId).toyProperty = value; }
}
And to resolve the .toyProperty pseudo-code you would have to use reflection or reflection+expressions.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
modified 17-May-16 17:18pm.
|
|
|
|
|
After thinking about this for a couple of minutes, the answer is "probably yes", but the code ends up being hideously complex because of other property types outside of the string case you're showing. You have to handle all possible types through reflection, even structures and class instances.
This isn't something I've done, nor want to because of time.
|
|
|
|
|
As the others have said, this is probably possible but almost certainly not advisable!
You would lose type safety and compile-time checking for correct property identification, etc.
Here are my initial thoughts on how I'd do this.
public class Toy
{
public Toy(int id)
{
ID = id;
}
public int ID { get; private set; }
public double Price { get; set; }
public string Color { get; set; }
}
public class Merchandise
{
public Dictionary<int, Toy> toys;
public Merchandise()
{
var toyList = new List<Toy>();
toyList.Add(new Toy {ID = 1, Price = 10, Color = "Red"});
toyList.Add(new Toy {ID = 2, Price = 10, Color = "White"});
toyList.Add(new Toy {ID = 3, Price = 10, Color = "Black"});
toys = toyList.ToDictionary(t => t.ID);
}
public string this[int toyId]
{
get
{
Toy theToy;
toys.TryGetValue(toyID, out theToy);
return theToy;
}
}
}
Then the usage is:
public double price = txtPrice.Text;
public string color = txtColor.Text;
public Merchandise item = new Merchandise();
item[2].Price = price;
item[2].Color = color;
Toy theToy = item[2];
if (theToy != null)
{
theToy.Price = price;
theToy.Color = color;
}
else
{
}
"Fairy tales do not tell children the dragons exist. Children already know that dragons exist. Fairy tales tell children the dragons can be killed."
- G.K. Chesterton
|
|
|
|
|
Thank all for your valuable inputs especially you Matt. The purpose of this project was just to explore how to dynamically choose a property to be inserted into a LINQ query at runtime. I've learned a lot from everyone's input.
I was able to do what I had originally set out to do using the code below although it is not as elegant as your solution.
public string this[int toyId, string price, string color]
{
get
{
string result = string.Empty;
if (color != null)
{
result = toyList.FirstOrDefault(toy => toy.ID == toyId).Color;
}
else if (price != null)
{
result = (toyList.FirstOrDefault(toy => toy.ID == toyId).Price).ToString();
}
return result;
}
set
{
if (color != null)
{
toyList.FirstOrDefault(toy => toy.ID == toyId).Color = value;
}
else if (price != null)
{
toyList.FirstOrDefault(toy => toy.ID == toyId).Price = Convert.ToDouble(value);
}
}
}
|
|
|
|
|
This still suffers from the problems that I mentioned.
It isn't even close to type-safe.
You'll get a NullReferenceException if the toyId isn't found, unless both price and color are null , in which case you'll never know!
For the "price" case, if the string is not a valid double , it will throw a FormatException (or, less likely, OverflowException ).
This is the wrong place in a design to be parsing the price value string to double !
It ought to be done as near as possible to where the user provides the input so it can be reported appropriately.
Finally, in fact, you did not "dynamically choose a property to be inserted into a LINQ query at runtime".
You're choosing different properties of the result of identical LINQ queries based on boolean conditions represented by string values being null or not.
I would consider this abuse of the indexer to gain a syntactic shortcut of very dubious value.
So lesson learned.
Don't do this in production code!
(Or any code! )
This is serious "code smell".
I'm sorry, but it needed to be said.
"Fairy tales do not tell children the dragons exist. Children already know that dragons exist. Fairy tales tell children the dragons can be killed."
- G.K. Chesterton
|
|
|
|
|
Restated another way, the question is how to update an existing item in a collection using LINQ:
List<Toy> toys = new List<Toy>();
toys.Add( new Toy() { Id = 1, Color = "Red", Price = 1.20M } );
toys.Add( new Toy() { Id = 2, Color = "Red", Price = 1.20M } );
toys.Add( new Toy() { Id = 3, Color = "Red", Price = 1.20M } );
toys.Single( o => o.Id == 2 ).Color = "Blue";
toys.Single( o => o.Id == 2 ).Price = 3.99M;
toys.ForEach( o => Console.WriteLine( $"{o.Id} {o.Color} {o.Price}" ) );
|
|
|
|
|
I want to know a process what file create or delete or change in Windows or what manipulte registry keys? Is it possible in c#? Please suggest me how I should do it? Give me example or useful link. Thanks
|
|
|
|
|
Start by studying, and experimenting with, the System.FileWatcher class in .NET: [^]
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|
Thanks. FileWatcher can catch registry keys?
|
|
|
|
|
saeedmir wrote: FileWatcher can catch registry keys? It does not, as the name already implies.
You can do that easily yourself; make a copy of the parts of the registry you want to monitor, let your foreign application run and modify away, take another snapshot of those registry-parts, and compare those two.
Good luck
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|