|
|
Cool.
Thank you.
Thanks for your time
If you work with telemetry, please check this bulletin board: http://www.bkelly.ws/irig_106/
|
|
|
|
|
Oops, I have a follow up on this.
Declarations:
CFileException get_error_message;
const unsigned int ERROR_MAX = 64;
char char_error_text[ ERROR_MAX ];
LPTSTR ptr_error_text = &char_error_text[0];
CString final_error_message = "";
Code:
m_definition_file_name += "x";
try
{
m_definition_file.Open( m_definition_file_name, CFile::modeRead );
get_error_message.GetErrorMessage( ptr_error_text, ERROR_MAX, NULL );
final_error_message = char_error_text;
error_number = GetLastError();
}
catch( CFileException e )
{ code }
catch( ... )
{ code }
{
The line m_definition_file_name += "x" forces the file name to be incorrect.
Char array char_error_text winds up with "No error occurred." while error_number gets 0 (zero)
When the line error_number = GetLastErrror is moved directly beneath the open command, it get the value 2 (two). But that consumes the last error and get_error_message does not get anything.
Nothing is thrown and neither catch is activated.
What do I need to change to use this CFileException?
Thanks for your time
If you work with telemetry, please check this bulletin board: http://www.bkelly.ws/irig_106/
|
|
|
|
|
I don't understand what you are doing here; it should be:
try
{
}
catch (CFileException ce)
{
TCHAR message[132];
if (ce.GetErrorMessage(message, 132, NULL)
{
}
}
Use the best guess
|
|
|
|
|
Hello,
I don't see what you have different. Second, when the file does not exist, this Open method does not throw an exception, so none of the try/catch matters. I had a catch(...) at the bottom and it was not entered.
Thanks for your time
If you work with telemetry, please check this bulletin board: http://www.bkelly.ws/irig_106/
|
|
|
|
|
If the open function does not throw an error then you need to check the return value and call GetLastError() to find out why, as described here[^]. Alternatively you can throw a new exception like:
try
{
if (!m_definition_file.Open(m_definition_file_name, CFile::modeRead))
{
DWORD error_number = GetLastError();
throw new CFileException::OsErrorToException(error_number);
}
}
catch( CFileException e )
{
}
Note that when calling GetLastError() you must call it immediately after the failing API function call, otherwise its return may not be valid.
Use the best guess
|
|
|
|
|
I have also tried this.
Declarations:
const unsigned int ERROR_MAX = 64;
char char_error_text[ ERROR_MAX ];
LPTSTR ptr_error_text = &char_error_text[0];
CString final_error_message = "";
With this code
m_definition_file.Open( m_definition_file_name, CFile::modeRead );
error_number = GetLastError();
format_message_return = FormatMessage( 0, // dwFlags
NULL, // lpSousrce
error_number, // dwMessageID
NULL, // dwLanguageId
ptr_error_text, // lpBuffer
ERROR_MAX, // nSize
NULL ); // Arguments
final_error_message = char_error_text;
The error number is 2 (two). char_error_text ends up with nothing. I am uncertain of the arguments for FormatMessage. The file name is forced to be incorrect and an error is expected.
Thanks for your time
If you work with telemetry, please check this bulletin board: http://www.bkelly.ws/irig_106/
|
|
|
|
|
I have yet to get a text based error code for opening a file. Here is the simplified code:
m_definition_file_name = Select_Definition_File.GetPathName();
m_definition_file_name += "x"; m_definition_file.Open( m_definition_file_name, CFile::modeRead );
get_error_message.GetErrorMessage( ptr_error_text, ERROR_MAX, NULL );
final_error_message = char_error_text;
The Open method does not throw an exception. When GetLasError() is used, the error code is 2 (two).
The GetErrorMesssage yields No error returned, which is incorrect. The file could not be opened because it does not exist.
GetErrorMessage(...) is has three arguments about formatting the error message, but the error message is not an argument. I presume it gets the error message like GetLastError() does, but this appears incorrect.
How do I get a text string describing this error?
Thanks for your time
If you work with telemetry, please check this bulletin board: http://www.bkelly.ws/irig_106/
|
|
|
|
|
I gave you a suggested solution at http://www.codeproject.com/Messages/4583835/Re-CFileException-discover-reasons.aspx[^], which should throw an exception whose value would be CFileException::fileNotFound (error code 2). Did you try it, and if so what result did you get?
In response to your comment about FormatMessage , you need to tell the function where to look for the mappings of error codes to messages thus:
format_message_return = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error_number, NULL, ptr_error_text, ERROR_MAX, NULL );
This is explained in full detail in the documentation[^].
Use the best guess
|
|
|
|
|
My apologies for no replying sooner. I followed your advice and now have that FormatMessage method working. Thank you.
Thanks for your time
If you work with telemetry, please check this bulletin board: http://www.bkelly.ws/irig_106/
|
|
|
|
|
You're welcome.
Use the best guess
|
|
|
|
|
I have thousands lines of C++ codes which work well on small text files, but crashes on huge text files (such as 2 GB size). Crash reason: app eats up memory.
Is it possible to allocate memory from disk? Because in most case, hard disk space is much bigger than physical memory. If I can borrow some space from hard disk for my app and return them back after use, then my app has little chance to crash.
Here are my design thoughts:
1.Create a temporary file for file mapping(CreateFileMapping, OpenFileMapping)
2.Force my app to allocate memory from the temporary file
3.Do some clean up work: CloseFileMapping and delete the temporary file
Because I have so much existing code, if my design thought is reasonable, I don't want to redesign my project.
I'm not sure if the design thought is possible to implement. Anybody can help me?
PS: I'm using Visual C++ 2010.
|
|
|
|
|
The most elegant approach is to use MapViewOfFile to only map a smaller piece of the file at any one time, one that does fit into your address space, and then shift the view by Unmap/Map-ing.
In conjunction with this, a way to slightly extend the limit of what can fit in your address space is to set the /LARGEADDRESSAWARE compiler switch, which can be found under the properties. This tells the compiler that you are aware of that 32 bits pointer can use the full range of 0 - 2^32-1, rather than only half that range 2^31-1. With this, you might be able to reach up to ~3GB, depending on system configuration and your application. However, this only slightly shifts the available memory.
Using the above approach, you map the piece of file that you want to use into your address space, and as soon as you are done with the current piece you map the next, etc.
|
|
|
|
|
thank you for your advice, i will have a try.
|
|
|
|
|
We have a method using ippiFFT to perform forward and inverse FFT of an Image. This method calls ippiFFT 3 times. We try apply cilk_spawn with purpose improve performance of FFT processing, but processing speed of the method is slower than source without cilk_spawn (decreased about 1.5 times). We don't known what is the problem, please help us!
I will describe shortly here:
void performFFT(int start, int end, Ipp32fc[] image)
{
for(int i = start; i < end; i++)
{
ippiFFTInv(Image[i])....
ippiFFTInv(Image[i])....
ippiFFTFwd(Image[i])....
}
}
Source calls method performFFT without cilk_spawn:
Image[10];
performFFT(0, 10, Image);
Source calls method performFFT with cilk_spawn: (which is performance decrease 1.5 times)
Image[10];
cilk_spawn performFFT(0,5, Image);
performFFT(5,10,Image);
cilk_sync;
|
|
|
|
|
How to remove COM objects In-placed of regular DLLs in vc++ projects?
Prashant Gupta
|
|
|
|
|
Your question is not clear, please explain what problem you are trying to solve.
Use the best guess
|
|
|
|
|
Actually we are implementing a VC++ based application that use few COM objects, COM objects create problem when I think register them(not sure) during compilation.
So we want to replace COM objects by regular DLLs from our application.
I want to know the process that how to remove COM objects.
|
|
|
|
|
Prashant Gupta 241 wrote: So we want to replace COM objects by regular DLLs from our application.
I want to know the process that how to remove COM objects. There is no "process", you just need to rewrite the code where it makes calls to the COM interfaces, such that it uses regular function calls. I am not aware of any simplified method of doing this.
Use the best guess
|
|
|
|
|
Thank Richard
I have one more question
How to identify whether a module is dll or COM objects, so that we can easily identify and remove it.
its little bit confusing for us.
|
|
|
|
|
Prashant Gupta 241 wrote: How to identify whether a module is dll or COM objects Look at the documentation or source code. Although, you should know that from the implementation in your project.
Use the best guess
|
|
|
|
|
use inportt and outport commands
|
|
|
|
|
How to use that command I want to remove it from my code.
|
|
|
|
|
I am very very new to c++. I have been allowed lol to be a part of this c++ project. I am supposed to write a c++ dll that will export to c#. Anyways I am having trouble with class variables in functions that are exported. Could someone help me pleaser with this. Fyi we are using qt framework so that's why you see a few qt things. Basically it is crashing if I access a class variable which in this case is called testInt. this is not the actual code we are working with but it does duplicate the problem exactly as it occurs in the real code. The problem is my c# code crashes when the variable testInt is accessed but not if testInt2 is accessed.
header
#ifndef QTDDLLTESTCLASSVARIABLE_H
#define QTDDLLTESTCLASSVARIABLE_H
#include "qtddlltestclassvariable_global.h"
class QTDDLLTESTCLASSVARIABLE_EXPORT qtdDllTestClassVariable
{
public:
qtdDllTestClassVariable();
~qtdDllTestClassVariable();
void Test();
int testInt;
private:
};
#endif // QTDDLLTESTCLASSVARIABLE_H
#include "qtddlltestclassvariable.h"
#include <qDebug>
cpp file
qtdDllTestClassVariable::qtdDllTestClassVariable()
{
}
qtdDllTestClassVariable::~qtdDllTestClassVariable()
{
}
void qtdDllTestClassVariable::Test()
{
qDebug() << "started";
testInt = 5;
int testInt2 = 5;
qDebug() << testInt << " after int";
qDebug() << testInt2 << " after int2";
}
c# code
[DllImport(@"..\..\..\Win32\Debug\qtdDllTestClassVariable.dll", CharSet = CharSet.Unicode, EntryPoint = "?Test@qtdDllTestClassVariable@@QAEXXZ")]
public static extern void Test();
modified 1-Jun-13 15:51pm.
|
|
|
|
|
Using DLL Export you can export your C/C++ variables and functions to make them available. However, you can not just export an entire class and use it in C#.
The direct problem here is that you are accessing a member function (Test) without an instance of your test-class being created.
Probably the best way to interface in a class based manner between C++ and C# is to use COM; that is, create a COM class in C++, export it, and then use the COM class in C#.
|
|
|
|