|
|
How can I transcribe a Matlab image processing program (.m files) in C#?
|
|
|
|
|
It's a big question , you need to but your self , at some tutorials
I recommended to start from Here[^]
I know nothing , I know nothing ...
|
|
|
|
|
If you're looking to convert the code from Matlab to C#, you'll have to rewrite it from scratch, by hand. I don't know of any conversion tool that will do it for you.
|
|
|
|
|
|
Given that this is the C# forum, I'm going to say "no".
Mainly because the link doesn't refer to C# code, but C++.
You can't use that code in C#, and you shouldn't use it in C++ because - as it says at the top of the article - the function that refers to it has been superseded...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
OriginalGriff wrote: You can't use that code in C#
You sure?
[DllImport("user32", SetLastError = true, CharSet = CharSet.Auto)]
static extern bool InsertMenu(IntPtr hmenu, uint position, uint flags,
uint item_id, [MarshalAs(UnmanagedType.LPTStr)]string item_text);
|
|
|
|
|
Yes, ok, Mr Picky!
I was trying to simplify for a beginner that he was going the wrong way...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
OriginalGriff wrote: as it says at the top of the article - the function that refers to it has been
superseded...
Not entirely... keep reading the statement.
You can still use InsertMenu, however, if you do not need any of the extended features of InsertMenuItem.
|
|
|
|
|
You need more API functions than "InsertMenu" for Manipulating the System Menu Using C#
So Here you go Simple Class to do this[^]
I know nothing , I know nothing ...
|
|
|
|
|
I am trying to use any DLL in Windows 7 64 bit version. It give me exception "BadImageFormatException was unhandled". The same .dll works fine with Windows XP. The .dll was written in ASM and built using AnyCPU platform.
Here is the call in project:
[DllImport("library.dll")] static extern bool MyFunction(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
Anyone has come across it, is there a way to resolve it?
Best regards.
|
|
|
|
|
Here are some facts relating to 32/64 bit code:
1.
When you build a native-code DLL, you must decide whether you want it to use the 32-bit or the 64-bit architecture, which are both supported by most modern Intel/AMD processors.
2.
When you build a managed code DLL or EXE, you can choose between 32-bit, 64-bit, or automatic ("AnyCPU"). With 32-bit or 64-bit, it is the EXE itself that enforces the execution mode; with "AnyCPU" the EXE will run in 32-bit execution on 32-bit Windows, and in 64-bit execution on 64-bit Windows.
3.
And you can't mix 32-bit and 64-bit code in a single process, Windows simply doesn't allow a mode switch in mid execution, so the DLLs must match the EXE's mode (AnyCPU DLLs are always fine, the other managed ones and all unmanaged ones must match).
Assembly code is native code obviously, and 64-bit and 32-bit assembly source files look quite different, as the programming model is not the same at all. So I guess your "ASM DLL" really is a 32-bit beast, notwithstanding the fact that you created it on a 64-bit Win7 system.
So you could use your 32-bit native DLL, and use it on any 32-bit operating system (with a managed EXE built for x86 or for AnyCPU); or use it on a 64-bit OS with a managed EXE built for x86 (but not for "AnyCPU" as that would start in 64-bit mode and then fail to reference the DLL code).
In practice, you could simply rebuild the app (the EXE part should suffice) for x86, see the project properties. There also is a hack using CORFLAGS, which basically would alter the properties of an existing EXE file (not recommended when you have the source code anyhow).
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
modified on Saturday, April 30, 2011 5:16 PM
|
|
|
|
|
I tried to build my project as "AnyCPU", x86 and 64 bit, results are always the same: "BadImageFormatException was unhandled".
According to the guideline, I used CORFLAGS. After call: CorFlags.exe library.dll I have:
Error CF008 : The specified file does not have a valid managed header.
|
|
|
|
|
The compiler is expecting a managed library: did you add the library.dll to your project references? You should not do that if the library is native (non managed), the DllImport line should suffice.
|
|
|
|
|
I didn't add my library to references. Before (on x86) I didn't add also and it was OK.
|
|
|
|
|
The error message sometimes can be misleading, in fact it can also be raised if the loaded dll cannot find another library that it depends on. How is the ASM library compiled?
|
|
|
|
|
I think in Visual Studio. I don't know details, it's my friend's library, I didn't create it.
|
|
|
|
|
Where did you put the library?
it should be in a folder that is listed in the PATH environment variable.
As it probably is a 32-bit dll, it should NOT be put in C:\Windows\System32 (which is used only by 64-bit apps), Windows is confusing here, C:\Windows\SysWOW64 (which is used only by 32-bit apps) would be good though. Same applies to all dependencies of your dll file, if any.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
First I put it in folder when is file .exe. Now I put it to C:\Windows\SysWOW64, but application have error, that not found this library.
|
|
|
|
|
hi everyone,
this is my first post here.
i need a help please...
(i'm a beginner in c#)
i have to make two analog clocks with visual studio in c#,wich they must be in a different time zone beside each other,one with our time and the second could be any place in the world.
i made the first analog clock and than i copied it and i made a new class for it,but when i start debugging the second clock comes under the first one and attached to it,how can i move the second clock parallel to the right side of the first clock??
this is the main code wich contain the ode of the first clock:
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Drawing.Drawing2D;<br />
using System.Linq;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
<br />
namespace analoge_uhr<br />
{<br />
public partial class Form1 : Form<br />
{<br />
private Clock uhr1;<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
<br />
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);<br />
this.SetStyle(ControlStyles.UserPaint, true);<br />
this.SetStyle(ControlStyles.DoubleBuffer, true);<br />
uhr1 = new Clock();<br />
}<br />
protected override void OnPaint(PaintEventArgs e)<br />
{<br />
base.OnPaint(e);<br />
System.Drawing.Graphics gr = e.Graphics;<br />
<br />
Rectangle rec = new Rectangle(20, 20, 250, 250);<br />
LinearGradientBrush linearbrush = new LinearGradientBrush(rec, Color.Yellow, Color.Green, 225);<br />
gr.FillEllipse(linearbrush, 20, 20, 200, 200);<br />
linearbrush.LinearColors = new Color[] { Color.Silver, Color.Silver, };<br />
gr.FillEllipse(linearbrush, 30, 30, 180, 180);<br />
linearbrush.LinearColors = new Color[] { Color.Black, Color.Black };<br />
gr.FillEllipse(linearbrush, 33, 33, 174, 174);<br />
SolidBrush solidbrush = new SolidBrush(Color.White);<br />
Font textFont = new Font("Arial Bold", 12F);<br />
gr.DrawString("12", textFont, solidbrush, 109, 40);<br />
gr.DrawString("11", textFont, solidbrush, 75, 50);<br />
gr.DrawString("10", textFont, solidbrush, 47, 75);<br />
gr.DrawString("9", textFont, solidbrush, 43, 110);<br />
gr.DrawString("8", textFont, solidbrush, 52, 145);<br />
gr.DrawString("7", textFont, solidbrush, 75, 170);<br />
gr.DrawString("6", textFont, solidbrush, 113, 180);<br />
gr.DrawString("5", textFont, solidbrush, 150, 170);<br />
gr.DrawString("4", textFont, solidbrush, 173, 145);<br />
gr.DrawString("3", textFont, solidbrush, 182, 110);<br />
gr.DrawString("2", textFont, solidbrush, 173, 75);<br />
gr.DrawString("1", textFont, solidbrush, 150, 50);<br />
gr.TranslateTransform(120, 120, MatrixOrder.Append);<br />
int hour = DateTime.Now.Hour;<br />
int min = DateTime.Now.Minute;<br />
int sec = DateTime.Now.Second;<br />
Pen hourPen = new Pen(Color.White, 2);<br />
Pen minutePen = new Pen(Color.LightGray, 2);<br />
Pen secondPen = new Pen(Color.Red, 1);<br />
double secondAngle = 2.0 * Math.PI * sec / 60.0;<br />
double minuteAngle = 2.0 * Math.PI * (min + sec / 60.0) / 60.0;<br />
double hourAngle = 2.0 * Math.PI * (hour + min / 60.0) / 12.0;<br />
Point centre = new Point(0, 0);<br />
Point hourHand = new Point((int)(40 * Math.Sin(hourAngle)),<br />
(int)(-40 * Math.Cos(hourAngle)));<br />
gr.DrawLine(hourPen, centre, hourHand);<br />
Point minHand = new Point((int)(70 * Math.Sin(minuteAngle)),<br />
(int)(-70 * Math.Cos(minuteAngle)));<br />
gr.DrawLine(minutePen, centre, minHand);<br />
Point secHand = new Point((int)(70 * Math.Sin(secondAngle)),<br />
(int)(-70 * Math.Cos(secondAngle)));<br />
gr.DrawLine(secondPen, centre, secHand);<br />
<br />
uhr1.daw(e.Graphics);<br />
<br />
Invalidate();<br />
}<br />
<br />
} <br />
}<br />
and here is the code for the second clock,wich i opened for it a new class:
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Text;<br />
using System.Drawing;<br />
using System.Drawing.Drawing2D;<br />
<br />
namespace analoge_uhr<br />
{<br />
class Clock<br />
{<br />
<br />
public void daw(System.Drawing.Graphics g){<br />
<br />
Rectangle rec = new Rectangle(20, 20, 250, 250);<br />
LinearGradientBrush linearbrush = new LinearGradientBrush(rec, Color.Blue, Color.BlueViolet, 225);<br />
g.FillEllipse(linearbrush, 20, 20, 200, 200);<br />
linearbrush.LinearColors = new Color[] { Color.Silver, Color.Silver, };<br />
g.FillEllipse(linearbrush, 30, 30, 180, 180);<br />
linearbrush.LinearColors = new Color[] { Color.Black, Color.Black };<br />
g.FillEllipse(linearbrush, 33, 33, 174, 174);<br />
SolidBrush solidbrush = new SolidBrush(Color.White);<br />
Font textFont = new Font("Arial Bold", 12F);<br />
g.DrawString("12", textFont, solidbrush, 109, 40);<br />
g.DrawString("11", textFont, solidbrush, 75, 50);<br />
g.DrawString("10", textFont, solidbrush, 47, 75);<br />
g.DrawString("9", textFont, solidbrush, 43, 110);<br />
g.DrawString("8", textFont, solidbrush, 52, 145);<br />
g.DrawString("7", textFont, solidbrush, 75, 170);<br />
g.DrawString("6", textFont, solidbrush, 113, 180);<br />
g.DrawString("5", textFont, solidbrush, 150, 170);<br />
g.DrawString("4", textFont, solidbrush, 173, 145);<br />
g.DrawString("3", textFont, solidbrush, 182, 110);<br />
g.DrawString("2", textFont, solidbrush, 173, 75);<br />
g.DrawString("1", textFont, solidbrush, 150, 50);<br />
g.TranslateTransform(120, 120, MatrixOrder.Append);<br />
int hour = DateTime.Now.Hour;<br />
int min = DateTime.Now.Minute;<br />
int sec = DateTime.Now.Second;<br />
Pen hourPen = new Pen(Color.White, 2);<br />
Pen minutePen = new Pen(Color.LightGray, 2);<br />
Pen secondPen = new Pen(Color.Red, 1);<br />
double secondAngle = 2.0 * Math.PI * sec / 60.0;<br />
double minuteAngle = 2.0 * Math.PI * (min + sec / 60.0) / 60.0;<br />
double hourAngle = 2.0 * Math.PI * (hour + min / 60.0) / 12.0;<br />
Point centre = new Point(0, 0);<br />
Point hourHand = new Point((int)(40 * Math.Sin(hourAngle)),<br />
(int)(-40 * Math.Cos(hourAngle)));<br />
g.DrawLine(hourPen, centre, hourHand);<br />
Point minHand = new Point((int)(70 * Math.Sin(minuteAngle)),<br />
(int)(-70 * Math.Cos(minuteAngle)));<br />
g.DrawLine(minutePen, centre, minHand);<br />
Point secHand = new Point((int)(70 * Math.Sin(secondAngle)),<br />
(int)(-70 * Math.Cos(secondAngle)));<br />
g.DrawLine(secondPen, centre, secHand);<br />
<br />
}<br />
}<br />
<br />
}<br />
<br />
and thanky you...
modified on Saturday, April 30, 2011 4:31 PM
|
|
|
|
|
Hi,
welcome to CodeProject.
A few suggestions for starters: there is a nice message "How to get an answer..." somewhere high up on this page; I suggest you read it carefully. It will tell you to provide a better subject line, to format your code (by using PRE tags), and many other things all helping you to get more answers, resulting in better and earlier feedback.
I did not study all that code (as it isn't in PRE tags, you can still edit the existing message!) however I can tell you this:
1.
it isn't object oriented. You should never copy-paste a bunch of code just because you want two identical or almost identical things somewhere. That most likely gets handled by creating a class (=a set of code and data pertaining to a real-world object (or maybe something more abstract).
2.
Furthermore, an AnalogClock should be a class that inherits from UserControl, so you can turn it into a separate DLL file, making it available to all kinds of WinForms applications, just like the standard Buttons, Labels and all known Controls. I suggest you read up on UserControl, and maybe search for some CodeProject articles on analog clocks while you're at it.
3.
Controls (and other classes) can have Properties, that is how you would specify e.g. their location on a Form. Or their offset from GMT (their time zone).
4.
there are more elegant ways to draw the digits, a for loop driven by a coordinates array comes to mind. Anything would be better than a sequence of
gr.DrawString("12", textFont, solidbrush, 109, 40);
gr.DrawString("11", textFont, solidbrush, 75, 50);
gr.DrawString("10", textFont, solidbrush, 47, 75);
...
5.
When you create drawing objects such as Fonts, Pens, Graphics, etc, you should clean up after yourself (yes, the GC does that also, however it does it late, and graphics objects can be expensive). So check if the class has a Dispose() method, and if it does, use it.
There are two alternatives:
- create those objects once, and keep them around as class members inside your AnalogClock class;
- or use a using statement (read up on it, it is perfect for these kinds of things).
There may be more, however that should get you started in the right direction.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
thanks 4 ur reply,i would notice that...
|
|
|
|
|
I want to make a wysiwyg program in c#, that is composed from a webbrowser control and a form1.
Inside form1 I want to make some search through files(mostly simple txt files) and if needed some extraction from zipped files. That is the main purpose of that form1 made in c#. In the webbrowser control I want to load txt files,generate menus with those txt files, html pages(local or online). All of these I will edit INSIDE that webcontrol through javascript-html-css on the fly(or edit the source file itself).
Why? because is so easy to make allmost anything in a html format-its more intuitive.
Most of the things that this program should do is for local files management => meaning tutorials, hints,tips, snippets,codes,thoughts,comments,pictures,etc.
That is what I want to do.
Now, my question is like this:
How do I take the content from a javascript variable, and paste it into a c# variable?
(The revers situation when i must copy content from a c# variable, I usually save that content in a txt file,then read that file in a javascript variable.)
thank you.
|
|
|
|
|
You don't. Javascript doesn't know anything about C# nor does it even know that it's running inside of a webbrowser control inside your Windows Forms app.
|
|
|
|
|
merlinq12 wrote: How do I take the content from a javascript variable, and paste it into a c# variable?
Call a webservice
I are Troll
|
|
|
|
|