|
Ok
It's one of those things where another of section of code was causing the problem. It had nothing to do with the array. Problem fixed array transfered properly.
Say it with me now, ROOKIE!!!!!!!!!!!!!!
I do appreciate the expediant answers. Consider this line/thread closed
Thanks
L.
|
|
|
|
|
Hi Everyone,
I have a project which was written long time back. Now we are in position to convert into C# source code but we found that we donot have any source code.
I need two favors from you.
1. How to convert the ocx file into C# source code without having the source code
2. How to convert VC++ source code into C# soruce code.
Thanks in advance
|
|
|
|
|
dwark106 wrote:
1. How to convert the ocx file into C# source code without having the source code
Why? If your COM component works well, just use it in a C# application (via COM interop ).
If you're stuck with the 'conversion' requirement, I suppose the easier solution is implementing from scratch the COM object functionality (i.e. 'the black box' way) in C# (in other words, I believe reverse engineering is not a good solution of your problem).
dwark106 wrote: 2. How to convert VC++ source code into C# soruce code.
For a C++ and C# expert the task should be fairly straightforward (if you were an expert of both languages then you probably wouldn't do or ask about...).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi Pallini,
Thanks for your response.
1. Actually I donot know what are the functions are being used by this application(ocx). I am also thinking to write from the scratch, but I do not have source code, so that I can chop the function that is not needed.
2. I was looking the easier way to convert the application. Anyways I will take your suggestions.
|
|
|
|
|
1) Learn assembler. Disassemble OCX. Spend lots of time working out what the heck is going on. Code it in c#
2) Learn C++. Learn C#. Translate.
To be honest, if you are lacking the source code for the OCX, then the best thing you can do is re-write it from the original specification. Or (more likely) write the spec from the OCX behaviour, and then rewrite the OCX.
Good luck - you may need it...
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
There are no conversion tools and nothing that is going to generate any kind of C# code for you. You have no choice but to study the existing OCX control and redesign and recode the control by hand in C#, or any other language for that matter.
|
|
|
|
|
I don't know how to put timer in form that clock would be moving..
public void Start()
{
timer1.Enabled = true;
this.Refresh();
}
public void Stop()
{
timer1.Enabled = false;
}
private void timer1_Tick_1(object sender, EventArgs e)
{
this.dateTime = DateTime.Now;
this.Refresh();
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
dateTime = DateTime.Now;
this.analog_size(sender, e);
}
With this code i get current time and clock pointers are also showing the correct time..but they are not moving..what should i do to make them move??
Thanks
|
|
|
|
|
As far as I can see you wait for the timer to tick, but the timer isn't ticking. In Start() and Stop() methods you should use timer1.Start() and timer1.Stop() rather than timer1.Enabled .
Still learning...
|
|
|
|
|
Thanks...but i found out there was problems with drawing seconds pointer...so both enabled and .start works now. Thanks anyway
|
|
|
|
|
How to make lets say new timer timer2_tick...to start ticking from 0 when start button pressed and everytime seconds come till 60 1 minute ++...when minutes come to 60..1 hour ++...and end when stop button pressed..i have to build stopwatch in other words..Now clock for datetime.Now works..so some little changes and stopwatch will work to..
Thanks for any help
|
|
|
|
|
I am building a desktop application and I want to add a column to a gridview to display an image for each record based on the value of a column in the database.
Example: If the status column for a record is ready the image column would show a ticky and if the status is error it would show a X.
Thanks much
|
|
|
|
|
If you actually mean that you are using a DataGridView control and you are using VS2008/VS2005 there is a DataGridViewImageCell class.
Look up the documentation, there are examples in there.
Try it out and if you get stuck, post the code where the problem is, and a description of the problem. I'm sure you'll get some assistance.
Good luck!
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
My app is two parts: main executable is in C#, and the core of the app is mixed native C++ with C++/CLI. The native parts use ffmpeg's libavcodec family of api's to grab select frames from a video, do some processing on them, encode them as jpeg, and then return the encoded jpeg data as a (managed) byte[] array back to the main c# app.
The app is fast, and makes a lot of allocations - there are maybe 5 frames of jpeg data returned to the main app per second, and each frame is 4.6 MB in size.
The problem is that memory usage creeps up. Short runs of the program it doesn't matter, but longer runs and I run out of memory.
The C++/CLI part of the app returns the data to the C# app simply by calling a callack funtion with a byte[] parameter.
I'm sure there are no leaks in the native code part of the app; if i comment out the line that calls the callback then the app runs forever without leaking memory.
I can therefore play with the code in the callback function - most of it is superficial and can be commented out. But the one line that seems to cause the problem is when I write the byte array to a (previously created) BinaryWriter (which is tied to a FileStream):-
m_outputFile = new FileStream(@"C:\filename.bin", FileMode.Create, FileAccess.Write);
m_outputWriter = new BinaryWriter(m_outputFile);
public void ReturnFrame(byte[] frameData)
{
m_outputWriter.Write(frameData);
}
With the code like that, memory usage just keeps increasing until i run out of memory.
If I comment out the m_outputWriter.Write(frameData) line, memory usage remains in check for the entire runtime of the program. There are no other references to frameData - the caller had the only other one, which is nulled asap, as shown here.
void EncodeThread(Object^ o)
{
array<Byte>^ jpegData = gcnew array<Byte>(Width * Height * 3);
Marshal::Copy(IntPtr(pRgbFrame->data[0]),jpegData,0,Width * Height * 3);
m_callback->ReturnFrame(jpegData);
jpegData = nullptr;
}
I've tried adding a GC.Collect() after the offending line, but it doesn't make any difference.
I'm really confused as to what is going on here. The GC just doesn't seem to want to collect my garbage!
Any ideas?
Thanks
Jon
|
|
|
|
|
Hi,
several questions:
1. how are you setting the callback?
2. what is (or would be) the prototype of the callback in native C++?
3. who is allocating and freeing the (native?) buffer that the callback is assumed to consume?
4. don't you close the file (m_outputWriter and m_outputFile)? without it, the stream grows bigger and bigger.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Luc Pattyn wrote: 1. how are you setting the callback?
My main form in the c# app implements an interface, ICaptureCallback, which looks like this:-
interface ICaptureCallback
{
void ReturnFrame(byte[] frameData);
}
The C++/CLI class that calls this takes an ICaptureCallback parameter in it's contstructor.
Luc Pattyn wrote: 2. what is (or would be) the prototype of the callback in native C++?
Not sure why this is relevant; the callback is implemented solely in managed code.
Luc Pattyn wrote: 3. who is allocating and freeing the (native?) buffer that the callback is assumed to consume?
The data originates in a native buffer from ffmpeg, but these lines of code:-
array<Byte>^ jpegData = gcnew array<Byte>(Width * Height * 3);
Marshal::Copy(IntPtr(pRgbFrame->data[0]),jpegData,0,Width * Height * 3);
m_callback->ReturnFrame(jpegData);
jpegData = nullptr;
which are from the C++/CLI class that does the call show that the data is Marshal.Copy'd into a managed byte array. Although I've not shown the code, I'm confident that the native buffer is properly freed.
Luc Pattyn wrote: 4. don't you close the file (m_outputWriter and m_outputFile)? without it, the stream grows bigger and bigger.
Because the objective of this app is to store the frames in a big binary file. Other code, which I've removed from the callback stored the offsets and frame sizes for later use. To close the file would stop the exact designed functionality of the app. Note, that the file is a disk file, not a memory stream, so should only get big on the disk, not take up much ram.
thanks for your interest.
Jon
|
|
|
|
|
Hi Jon,
I think I start to get the overall picture now.
Here are some thoughts:
1. your buffers are "large", i.e. larger than 85KB, hence allocated on the large-object-heap LOH which never gets compacted, and therefore is subject to fragmentation (unless all objects have the exact same size). In extreme cases fragmentation could mean your app is really using only a few megabytes, yet fails to allocate one more megabyte.
Remember: collections such as lists are implemented as arrays, not linked lists, so whenever their count exceeds the next power of two, the array gets reallocated with twice the size, potentially also invading the LOH.
2.
The line jpegData = nullptr; probably is not relevant since in the previous line (m_callback->ReturnFrame(jpegData); ) you passed the reference to another method, which could store it somehow, and hence keep the array alive.
3.
You may have a performance problem: with 5 frames per second, you need an overall throughput of 23MB/sec which you copy once with Marshal.Copy, copy once more with m_outputWriter.Write, and finally the system must dump to the disk in order for the memory to become available again. That could be beyond your system's capabilities; watch Task Manager and/or experiment with less data (smaller frames, or fewer frames per second, maybe skip every second frame).
4.
Maybe you could simplify things (and reduce the system load) by passing a ready-made buffer to your native code, rather than have it allocate, fill, copy and deallocate. That is how I have always done image processing in mixed environments.
If all the data needs to go through is generate natively and write to a managed file, you could do that with just one array, using it over and over.
Hope this helps. If you need more detailed discussions, I'd probably want to see ALL code relevant to allocating, pinning. copying and freeing buffers.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Hello,
I have two forms; one is the main form and the other the Delimiter form. The first form gets the file extension and location from the user. The second form is used when the user selects .txt files. The second form captures the delimiter of the .txt file then is closed when the "OK" button is clicked. Here is where I am having the problem. I need the delimiter info the user inputs, which is a text box on the second form, to be called in the connection string. I have tried a couple of things but the only delimiter I can get to work is when I hard code this into the connection. Can someone please help me? Here is what I have:
First form:
String comString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path.GetDirectoryName(FilePath) + @";Extended Properties=""text;HDR=YES;FMT=Delimited(TAB)""";
Second form:
string GD;
GD = textBox1.Text;
What I would like to do is something like:
String comString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path.GetDirectoryName(FilePath) + @";Extended Properties=""text;HDR=YES;FMT=Delimited["+ GD +")"; --This doesn't work
Thank you!
|
|
|
|
|
bwood2020 wrote: =Delimited["+ GD +")";
Try replacing '[' with '(' - it may help!
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Thank you for your reply!
Sorry, that was a typo on my part. I had ["+ GD +"]. GD doesn't show up in the popup but the name of the second form does (GetDelimiter). I used this as well but it throws the error:
GetDelimiter is a 'type' but is used like a 'variable'.
When I use GD it throws the error:
GD does not exist in the current context.
What am I doing worng here?
Thank you!
|
|
|
|
|
If I understand you correctly, you want to get a value from the second Form in the first?
If so, create a public property or method in the second Form, and call that from the first using the instance of the second Form.
string specialText = form2.TextIWant
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Yes, that is correct. I want to capture the value from the second form and use it in the first.
in the second form I have this:
public void textBox1_TextChanged(object sender, EventArgs e)
{
string GD;
GD = textBox1.Text;
}
then I am calling it in the first form with this:
String comString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path.GetDirectoryName(FilePath) + @";Extended Properties=""text;HDR=YES;FMT=Delimited("+ GD +")";
Both methods were made public before posting. Should have mentioned that.
When I declare another string in the first it only allows me to write:
string GDS = GetDelimiter.GD
This throws an error:
Doesn't contain a definition for GD.
|
|
|
|
|
Keep a reference to the second form when you instanciate it and use that reference.
A simple example. Button on Form1, TextBox on Form2:
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private Form2 form2;
public Form1()
{
InitializeComponent();
form2 = new Form2();
form2.Show();
}
private void button1_Click(object sender, EventArgs e)
{
if (form2 != null)
MessageBox.Show(form2.GD);
}
}
}
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
GD = textBox1.Text;
}
public string GD
{
get;
set;
}
}
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Having a problem with get and set. The error I receive for:
public void textBox1_TextChanged(object sender, EventArgs e)
{
GD = textBox1.Text;
}
public string GD
{
get;
set;
}
Error: get and set must declare a body because it is not marked abstract or extern.
I tried adding some code to get and set and I received this error:
public void textBox1_TextChanged(object sender, EventArgs e)
{
//GD = textBox1.Text;
}
public string GD
{
get { return GD; }
set { GD = value; }
}
Error:Make sure you do not have an infinite loop or infinite recursion.
Any ideas?
|
|
|
|
|
The problem is caused by your new public property. Change the case of the field references.
Change:
public string GD
{
get { return GD; }
set { GD = value; }
}
to:
public string GD
{
get { return gd; }
set { gd = value; }
}
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Sorry, I'm not following. As you can guess I am not a very good programmer. Just starting out and I thank you for your patience. I do not have any private fields in the second form. Do I need to declare gd as private? Something like:
public void textBox1_TextChanged(object sender, EventArgs e)
{
GD = textBox1.Text;
gd = GD;
}
private string gd;
public string GD
{
get { return gd; }
set { gd = value; }
}
|
|
|
|