I am trying to compile the following code fragment in vc++ 2010 (using /cli flag):
AVFrame * m_Decoded = av_frame_alloc();
av_frame_free(&m_Decoded);
However, the second line throws an error:
error C2664: 'av_frame_free' : cannot convert parameter 1 from 'cli::interior_ptr' to 'AVFrame **'
Any idea how to bypass this problem?
Thanks!
Ofer
Did you try pin_ptr?
pin_ptr<AVFrame*> ptr = &m_Decoded;
av_frame_free( ptr );
Related
I have a function definition like this:
double getPriceTimeByPtr(const StrategyParams* ptr, const int applied_price, const int timeframe, const int shift, const int shift_delta, const bool normalized, time_t &time);
but when I compile this code it errors just before the &time part so clearly there is a problem passing a time_t object by reference.
How do I fix this please?
I recently added the time_t parameter to the function and the error occurred since then.
Here's the errors generated:
Severity Code Description Project File Line Suppression
State
Error C2143 syntax error: missing ')' before '&'
Error C2143 syntax error: missing '{' before '&'
Error C2059 syntax error: '&'
Error C2059 syntax error: ')'
The syntax seems correct to me but the compiler doesn't like it.
The project that was failing was defined as a C project which was then trying to call a C++ function by reference. C can't us by reference so was failing. Changing the time parameters to pointers worked.
I have an c++ example project from an USB 3.0 Interface vendor called streamer application from cypress fx3. I wanted to get this to run first and see the potential behind the application but unfornately I'm getting a whole set of errors when building in Visual Studio 2017.
I get errors in the main file streamer.cpp showing me the errors:
Error (active) E0079 expected a type specifier Line 26
Error (active) E1986 an ordinary pointer to a C++/CLI ref class or interface >class is not allowed Line 28
in Code:
#include "stdafx.h"
#include <windows.h>
// windows.h includes WINGDI.h which
// defines GetObject as GetObjectA, breaking
// System::Resources::ResourceManager::GetObject.
// So, we undef here.
#undef GetObject
#include "Streamer.h"
#undef MessageBox
using namespace System::Windows::Forms;
using namespace Streams;
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
System::Threading::Thread::CurrentThread->ApartmentState =
System::Threading::ApartmentState::STA;
try
{
Application::Run(new Form1()); // THIS IS LINE 26
}
catch (Exception *e) // THIS IS LINE 28
{
MessageBox::Show(e->StackTrace,e->Message);
}
return 0;
}
Form 1 is part of streamer.h . In streamer h the error amount exceedes 400.
Most often compiler tells me identifier expected (E0040) even for syntax like private and public. Then the "this" operator causes an error:
Error (active) E0258 'this' may only be used inside a nonstatic member >function
What I tried to get this running:
- Installing missing windows sdk version 8.1 via installation routine in windows system control
- Changing Common Language Runtime Support to /clr
- inluding all missing header-files, compiler is now finding these header files.
Seems to me that there is something missing in the source project. Can you push me in the right direction?
catch (Exception *e)
That is an unmanaged exception. You need to catch a managed exception:
catch (Exception^ e)
I have this part of code that was compiling using ARMASM :
/* Software Interrupt */
/* we must save lr in case it is called from SVC mode */
#define ngARMSwi( code) __asm { SWI code,{},{},{lr} }
example of use :
ngARMSwi( 0x23);
I try to convert this to compile using gcc (code sourcery GCC-4.6.2 eabi). I found this link http://www.ethernut.de/en/documents/arm-inline-asm.html but I cannot find a way to compile this line correctly.
my best try is
#define ngARMSwi( code) __asm__ ("SWI " (code) : : :"lr" )
but I get compile error :
error: expected ':' or ')' before '(' token
Any help is appreciated!
You probably want
#define ngARMSwi(code) __asm__("SWI %0" : : "I"(code) : "lr")
Note that code is an input to the instruction, so it goes in the third section. Its place in the instuction is marked by the %0 in the string. The I is a constraint on code, indicating that it must be an 8-bit constant.
I had mysterious bug in loading Vorbis Ogg files on Mac OSX. The first file is loaded correctly, the second crashes in some code that indicates the file is corrupted, the same happens even if I load the same exact file twice.
After long hours of deep debugging inside Vorbis I found out that the bug is caused by the system function "pow" (double power of) returning a (nan) for a completely valid input, and that happens only on the second call to (ov_read), on the first call the same exact values passed to "pow" returns valid result.
8 hours later and lots of Intel x87 documentation reading I found the problem. Long story short there is a function deep inside vorbis "vorbis_ftoi " that uses this assembly code:
__asm__("fistl %0": "=m"(i) : "t"(f));
Which should push and pop on the Intel FPU Stack. However on LLVM it generates this code:
fld QWORD PTR [ebp-0x20]
fist DWORD PTR [ebp-0x14]
Which pushes on the stack but never pops causing an FPU stack overflow. And that's obviously a bug in LLVM
The proper code generated by GCC looks like this:
fld QWORD PTR [ebp-0x20]
fist DWORD PTR [ebp-0xc]
fstp st(0) // pops off the stack
I wasted a day and a half and some bytes of my brian learning some garbage (x87 Instruction Set and Registers) on this, so I though I would share it.
Auday
Simpler patch, has affect only when compiling with llvm:
--- Xiph\vorbis\os.h Mon Mar 28 08:42:43 2011
+++ Xiph\vorbis\os.h Thu Feb 02 14:20:27 2012
## -81,7 +81,7 ##
/* Special i386 GCC implementation */
-#if defined(__i386__) && defined(__GNUC__) && !defined(__BEOS__)
+#if defined(__i386__) && defined(__GNUC__) && !defined(__BEOS__) && !defined(__llvm__)
# define VORBIS_FPU_CONTROL
/* both GCC and MSVC are kinda stupid about rounding/casting to int.
Because of encapsulation constraints (GCC can't see inside the asm
Unfortunately, I don't have enough reputation to vote up the OP, but know that I'm grateful for your find. Thank you.
Excellent! Thank you. Another solution is to simply remove the asm altogether. Here is a patch:
--- lib/os.h 2011-11-13 20:36:24.000000000 -0500
+++ lib/os.h 2011-11-15 18:45:00.000000000 -0500
## -93,27 +93,16 ##
typedef ogg_int16_t vorbis_fpu_control;
static inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
- ogg_int16_t ret;
- ogg_int16_t temp;
- __asm__ __volatile__("fnstcw %0\n\t"
- "movw %0,%%dx\n\t"
- "andw $62463,%%dx\n\t"
- "movw %%dx,%1\n\t"
- "fldcw %1\n\t":"=m"(ret):"m"(temp): "dx");
- *fpu=ret;
}
static inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
- __asm__ __volatile__("fldcw %0":: "m"(fpu));
}
/* assumes the FPU is in round mode! */
static inline int vorbis_ftoi(double f){ /* yes, double! Otherwise,
we get extra fst/fld to
truncate precision */
- int i;
- __asm__("fistl %0": "=m"(i) : "t"(f));
- return(i);
+ return (int)floor(f+.5);
}
#endif /* Special i386 GCC implementation */
I have been struggeling writing a solution excisting out of an c++ win32console and a c++ dll. i finally managed to get them talking without linker errors (so i am assuming both are fully managed c++/CLI projects) but when i run the console i get the following error.
Unhandled exception at 0x03f71849 in
Company.Pins.Bank.Win32Console.exe:
0xC0000005: Access violation writing
location 0x00000001.
The console also shows the following
Unhandled Exception:
System.NullReferenceException: Object
reference not set to an instance of an
object. at wmain in c:...\win32console.cpp:line
20 at _wmainCRTStartup()
but i am assuming this is because of the unhandled exception.
tracking down this error as well as i can the error occurs when doing the return in the below code block. (the method linked by the return seems to step through fine, just when returning it seems to go bad.) Just in case you hadn't noticed, i did not write the below code myself, it was generated by visual studio.
#ifdef WPRFLAG
int wmainCRTStartup(
#else /* WPRFLAG */
int mainCRTStartup(
#endif /* WPRFLAG */
#endif /* _WINMAIN_ */
void
)
{
/*
* The /GS security cookie must be initialized before any exception
* handling targetting the current image is registered. No function
* using exception handling can be called in the current image until
* after __security_init_cookie has been called.
*/
__security_init_cookie();
return __tmainCRTStartup();
}
#include "stdafx.h"
#include "UInstruction.h"
#define DllExport __declspec(dllexport)
#define DllImport __declspec(dllimport)
using namespace System;
edit: and the win32console.cpp code is below.
//int main(array<System::String ^> ^args)
int _tmain(int argc, _TCHAR* argv[])
{
auto P2 = (TCHAR *)"3 Barrowstead";
TCHAR* P3 = (TCHAR *)"3 Barrowstead";
double* P1;
P1[0] = 13;
UserInstruction(P1, P2, P3);
}
You declare a pointer and do not initialize it so it doesn't point at an object (it contains some garbage address):
double* P1;
Then you try to write to wherever this uninitialized pointer points:
P1[0] = 13;
You cannot use an uninitialized variable. You need to initialize P1 to point at some object before you dereference it.
double* P1;
is uninitialized. You then attempt to set its first entry to 13. Boom, access violation, or worse.
Any of these snippets should work:
double P1;
P1 = 13;
UserInstruction(&P1, P2, P3);
or
double P1[1];
P1[0] = 13;
UserInstruction(P1, P2, P3);
or
double *P1 = new double[1];
P1[0] = 13;
UserInstruction(P1, P2, P3);
delete[] P1;
The following statements are also wrong when using UNICODE build:
auto P2 = (TCHAR *)"3 Barrowstead";
TCHAR* P3 = (TCHAR *)"3 Barrowstead";
because you're casting a normal (char) array to a wchar_t pointer.
if you build with UNICODE then you should change these in:
LPCTSTR P2 = _T("3 Barrowstead");
LPCTSTR P3 = _T("Barrowstead");
It is undefined behaviour to convert a string literal to a TCHAR*, as if UNICODE is defined then TCHAR* will become wchar_t*, and a string literal is not a wchar_t* and this pointer conversion is undefined.
I managed to find error the following way:
It was not in the line that the error poped-up.
It was actually in the last location I have PIN_PTR the memory.
I have used the following to copy a vector:
memcpy(&pined_ptr[0],&unmanagedvector[0],sizeofunmanagedvector);
The problem was PINED_PRT SIZE < unmanagedVectorSize ! Stupid error.
This messed up all managed memory, an expoded couple of lines & functions later.
How you can find in your code: Go disableling ranges of the code, until your code does not crash.