yeah, it's rubbish, isn't it. pos_type has an int64 member, but there's no operator overload to get that out -only an int.
using System.Beer;
yeah, it's rubbish, isn't it. pos_type has an int64 member, but there's no operator overload to get that out -only an int.
using System.Beer;
I'm working with very large files and i need to be able to get a 64bit stream position. ofstream::tellp() returns a streampos, which according to msdn is typedef fpos<mbstate_t> streampos; Whatever i try and cast the result to, it's wrong for files over 4GB- it's being truncated at 32 bits. What is odd is that according to mssn, fpos stores a byte offset of type streamoff, and a conversion state of type T. streamoff (according to msdn) is a long in win32 and an __int64 in win64. I am building under win32 but the debugger shows the private _Fpos member of fpos to be of type __int64. So, irritatingly, the 64 bit value is there in the fpos (i can see in the debugger, it's correct) but i can't get the value out. Any ideas? there must be a way of getting a 64bit file pos in win32.
using System.Beer;
Hi, I want to overlay controls on my main window that fade away and dissapear when the mouse is outside the window. Very much like in Windows Media Player. Is there a control to do that for me, or can anyone give me some starting information on how that might be achieved. thanks jon
using System.Beer;
Hi All, I'm using System.Diagnostics.Process for running a background task, from which i need to read the standard out and standard error. I'm doing this asyncronously with the Process.ErrorDataReceived, Process.OutputDataReceived events, and Process.BeginOutputReadLine() and Process.BeginErrorReadLine(). I also need to know when the process has exited, and i've received all the data. The problem is, that the Process.Exited event is fired before all of the data has been processed. I need to tidy up other stuff when the process has exited and all the data from stdout/stderr has been received. But I cannot for the life of me find a way of working out when that is the case. Can anyone help? thanks Jon
using System.Beer;
The [i]main[/i] reason? I can think of several more...
using System.Beer;
In C# you can tell the compiler not to expand escape sequences in string literals by prefixing the string with an @ symbol:-
string test = @"C:\test.jpg";
Is there an equivalent notation to do the same in VC++ ? (2008) thanks Jon
using System.Beer;
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
{
// other stuff removed
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
using System.Beer;
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):-
// the BinaryWriter is created like this
m_outputFile = new FileStream(@"C:\filename.bin", FileMode.Create, FileAccess.Write);
m_outputWriter = new BinaryWriter(m_outputFile);
// the callback function can have everything stripped out so it looks like this
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)
{
// irrelevant code removed here
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;
// irrelevant code removed here
}
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
sure. http://social.msdn.microsoft.com/forums/en-US/winforms/thread/25cceaa4-f058-482a-8381-03698f73651a/[^]
using System.Beer;
My app (which is part c++/cli and part c#) generates bitmaps on the fly, and they exist in memory initially as arrays of unsigned char (width * height * 3 bytes (rbg)). I need to be able to crop, resize, rotate (90, 180 degrees), mirror and flip these images in an efficient way. I've previously used GDI+, but GDI+ has some serious threading issues (although it allows multiple threads, only one thread per process actually gets executed by GDI+ at a time). So i need a replacement image processing library. I looked at CImg, but internally it organises data into separate arrays, one per colour channel, which would make it a headache to get my data into and out of the library. is anyone familiar with any other libraries which will meet my needs? could be c# or c++, it doesn't really matter.
using System.Beer;
Hi all, I have a custom winforms control. I want to be able to use anchor/dock type functionality in the form which hosts it, to facilitate dynamic resizing. Only thing is, my control must be square (ie width==height) to render properly. how can i force this to be the case? Thanks Jon
using System.Beer;
Thank for that, it's clear now. Looks like a can get around the issue with #pragma pack (2)
using System.Beer;
Hi all, I have a struct a bit like this, which is the header to a file on disk:-
struct Header
{
short a;
short b;
short c;
float floatvalue;
}
I read the header from the disk like this:-
ReadFile(hFile,&header,sizeof(Header),&bytesRead,NULL);
Once I'd done that, the values in a,b,c are as expected, but the floatvalue is not. However, if I adjust the struct so that instead of float, I have BYTE[4] as follows:-
struct Header
{
short a;
short b;
short c;
BYTE floatvalue[4];
}
And then after reading the header as before, I do:-
float f;
memcpy(&f,header.floatvalue,sizeof(float));
Then f contains the value expected. I don't understand why the first version didn't work. Can anyone enlighten me please? Thanks Jon
using System.Beer;
Sure, I realised I could engineer code to produce exactly that, but I wondered if it might have been built-in. Perhaps in the assembly meta data, and reflection would be able to find it. But I guess not. thanks anyway
using System.Beer;
I use conditional compilation symbols to enable and disable client cusomised parts of my code. Is there a built-in way to determine at run time what symbols were defined at build time?
using System.Beer;
The thing that confuses me is that &m_pFormatContext should be an unmanaged pointer, therefore AFAIU shouldn't need pinning?
using System.Beer;
I have a legacy C app which uses FFmpeg APIs. I'm trying to update it, I want to write a UI in C# and keep the core in C. So, i'm dabbling in C++/CLI for the first time. It's my understanding that I can create a managed class wrapper, and have managed methods which take managed parameters, convert them as necessary to unmanaged equivalents (with System.Runtime.InteropServices.Marshal methods), do the work in native C, and then convert outputs from unmanaged to managed types for return. However, I'm stuck at the start. I've created a class like this:-
ref class FFmpegCap
{
public:
FFmpegCap(String^ inputVideo);
protected:
AVFormatContext *m_pFormatContext;
};
In my constructor, i need to call a C FFmpeg function to initialise the library, one of the parameters it requires is of type AVFormatContext ** . So, I call this function as follows:-
if (av\_open\_input\_file(&m\_pFormatContext, pInputVideo ,NULL,0,NULL) != 0)
{
}
However, this fails to compile; error C2664: 'av_open_input_file' : cannot convert parameter 1 from 'cli::interior_ptr' to 'AVFormatContext **' It seems that the & operator is not doing what I expect of it! Any pointers? Thanks Jon
using System.Beer;
Thanks Iain, I should use my eyes more I think.
using System.Beer;
I have a legacy C app which uses FFmpeg APIs. I'm trying to update it, I want to write a UI in C# and keep the core in C. So, i'm dabbling in C++/CLI for the first time. It's my understanding that I can create a managed class wrapper, and have managed methods which take managed parameters, convert them as necessary to unmanaged equivalents (with System.Runtime.InteropServices.Marshal methods), do the work in native C, and then convert outputs from unmanaged to managed types for return. However, I'm stuck at the start. I've created a class like this:-
ref class FFmpegCap
{
public:
FFmpegCap(String^ inputVideo);
protected:
AVFormatContext *m_pFormatContext;
};
In my constructor, i need to call a C FFmpeg function to initialise the library, one of the parameters it requires is of type AVFormatContext ** . So, I call this function as follows:-
if (av\_open\_input\_file(&m\_pFormatContext, pInputVideo ,NULL,0,NULL) != 0)
{
}
However, this fails to compile; error C2664: 'av_open_input_file' : cannot convert parameter 1 from 'cli::interior_ptr' to 'AVFormatContext **' It seems that the & operator is not doing what I expect of it! Any pointers? Thanks Jon
using System.Beer;
imagine a struct declared as follows:-
typedef struct
{
int integerArray[];
} testStruct;
I can instantiate like this:-
testStruct a = {
{1,2,3}
};
Which is all well and good. But, if the struct declaration is changed to an int* member:-
typedef struct
{
int *integerArray;
} testStruct;
How can I now instantiate it so that integerArray points to my array of {1,2,3} ?? in gcc, you can cast {1,2,3} to (int *), as follows:-
testStruct a = {
(int *){1,2,3}
};
But msvc doesn't allow that. Is there another way to make this instantiation? thanks Jon
using System.Beer;