|
turbosupramk3 wrote: it seems like the byte array is valid Are you sure it contains a valid image? The error message suggests that it does not.
|
|
|
|
|
 No I am not, do you have a suggestion on another way I can check?
The code under the Exception snapshot, always has the same error message with the Parameter is not valid at
Quote: at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)
at System.Drawing.Image.FromStream(Stream stream)
at Updator.PictureUpdater.btnViewPicture_Click(Object sender, EventArgs e) in c:\Users\xxxx\Documents\Visual Studio 2012\Projects\Updator\Updator\Form1.cs:line 245
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Updator.Program.Main() in c:\Users\xxx\Documents\Visual Studio 2012\Projects\Exchange Picture Updator\Updator\Program.cs:line 19
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
modified 24-May-16 17:25pm.
|
|
|
|
|
I figured it out, I had to build my own byte array and not use memory stream. Memory stream was corrupting the file and making it an additional 28 bytes. I'm not sure why this wasn't on the internet, as it seems 100's of people encounter this?
Thanks for pointing me in the right direction.
byte[] imgBytes = null;
List<byte> imgBytesList = new List<byte>();
object imgObj = null;
Image img = null;
foreach (PSObject obj in exResults)
{
imgObj = obj.Properties["PictureData"].Value;
}
foreach (byte byt in (dynamic)imgObj)
{
imgBytesList.Add(byt);
}
imgBytes = imgBytesList.ToArray();
using (var ms = new MemoryStream(imgBytes))
{
img = Image.FromStream(ms);
}
pbxDisplayPicture.Image = img;
|
|
|
|
|
I have an application that uses a COM object to make a connection to an application. I need to make sure that when my application ends that I call the EndSession and CloseConnection methods of this COM object. I was reading this article: Implementing IDisposable and the Dispose Pattern Properly[^] as I think this is what I would need to do to make sure my closing code always gets called, but it doesn't seem to happen when I stop debugging. The application that I am connecting to still thinks my program is connected. It seems like when I stop debugging (or if I have a program crash, that the Dispose methods don't get called. I also tried to add a Finalizer but that causes a System.Runtime.InteropServices.InvalidComObjectException stating that the COM object that has been separated from it's underlying RCW cannot be used.
private bool disposed;
protected virtual void Dispose(bool disposing)
{
if (!disposed)
{
if (_Session != null)
{
_Session.EndSession();
_Session.CloseConnection();
_Session = null;
}
disposed = true;
}
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
~SessionConnection()
{
Dispose(false);
}
I'm not sure what is the best way to ensure that the EndSession and CloseConnection methods of my COM object get called even if my program crashes or I stop debugging.
|
|
|
|
|
I doesn't "seem" like you are sure if Dispose() is getting called so you should add a "log entry" in Dispose() to be sure.
Your "session" instance looks private.
You could try (pardon the pun), a higher level "try ... finally", where the finally always runs and checks your object for null, disposes it, etc.
Then there are application level exception handlers and "exits" ... you need to log to understand which paths your particular app can end on.
|
|
|
|
|
When you launch the code from inside Visual Studio, it's launched, the debugger is attached and you debug on your merry way. If you hit Stop inside Visual Studio, your code is stopped, wherever it is, and removed from memory. Your Dispose code never gets executed.
The only way to make sure it does is if you exit your application as a user would, gracefully.
|
|
|
|
|
That's what I was going to say!
The only thing I'd add is that the same thing will happen if you use Task Manager to kill the process. So if this is causing a problem with "Stop debugging" it'll also cause the same problem if the user terminates the app.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I never knew that about the debugger, thanks! But then does this mean that GC doesn't do any cleanup? Or is Visual Studio maintaining the information so it knows to release any allocated memory? Is this something to do with the VS Hosting Process? If I open a file within a using statement, it seems like stopping the debugger is still releasing the file handle (at least I think so, I'm still very new).
Are there any recommendations / best practices when dealing with situations like this?
|
|
|
|
|
There is no cleanup of the orphaned COM stuff. It's just left hanging. When the code is stopped abruptly, the GC doesn't even run. Your process is stopped cold and the memory the app and its data was occupying freed and returned to Windows.
The GC cannot clean up non-managed resources anyway. It can only cleanup managed stuff. The closest it can get is to free up the managed COM-wrapper that's is hanging onto the unmanaged COM references, but this doesn't free up those unmanaged resources. They are just orphaned.
The debugger doesn't release anything at all. It's just attached to the process, not executing or controlling it in any meaningful way.
|
|
|
|
|
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.
|
|
|
|
|