|
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#.
|
|
|
|
|
Hi all,
I have been trying to write encrypt and decrypt functions whose signatures require the input and the output strings to be in 'void*' type only. The code works fine if the inputs can be specified as IBuffer^ but in the other case the source string and the encrypted->decrypted string do not match. I've googled a lot but to no good. Please help...it's urgent.
IBuffer^ byteArrayToIBufferPtr(byte *source, int size)
{
Platform::ArrayReference<uint8> blobArray(source, size);
IBuffer ^buffer = CryptographicBuffer::CreateFromByteArray(blobArray);
return buffer;
}
byte* IBufferPtrToByteArray(IBuffer ^buffer)
{
Array<unsigned char,1U> ^platArray = ref new Array<unsigned char,1U>(256);
CryptographicBuffer::CopyToByteArray(buffer,&platArray);
byte *dest = platArray->Data;
return dest;
}
int DataEncryption::encryptData(EncryptionAlgorithm algo, int keySize, void* srcData, const unsigned int srcSize,
void*& encData, unsigned int& encSize)
{
LOG_D(TAG, "encryptData()");
if(srcData == nullptr)
{
LOG_E(TAG,"");
return DataEncryption::RESULT_EMPTY_DATA_ERROR;
}
if(srcSize == 0)
{
LOG_E(TAG,"");
return DataEncryption::RESULT_SIZE_ZERO_ERROR;
}
IBuffer^ encrypted;
IBuffer^ buffer;
IBuffer^ iv = nullptr;
String^ algName;
bool cbc = false;
switch (algo)
{
case DataEncryption::ENC_DEFAULT:
algName = "AES_CBC";
cbc = true;
break;
default:
break;
}
SymmetricKeyAlgorithmProvider^ Algorithm = SymmetricKeyAlgorithmProvider::OpenAlgorithm(algName);
IBuffer^ keymaterial = CryptographicBuffer::GenerateRandom((keySize + 7) / 8);
CryptographicKey^ key;
try
{
key = Algorithm->CreateSymmetricKey(keymaterial);
}
catch(InvalidArgumentException^ e)
{
LOG_E(TAG,"encryptData(): Could not create key.");
return DataEncryption::RESULT_ERROR;
}
if (cbc)
iv = CryptographicBuffer::GenerateRandom(Algorithm->BlockLength);
IBuffer ^srcDataBuffer = byteArrayToIBufferPtr(static_cast<byte*>(srcData),256);
encrypted = CryptographicEngine::Encrypt(key, srcDataBuffer, iv);
byte *bb = IBufferPtrToByteArray(encrypted);
encData = IBufferPtrToByteArray(encrypted);
encSize = encrypted->Length;
return DataEncryption::RESULT_SUCCESS;
}
int DataEncryption::decryptData(EncryptionAlgorithm algo, int keySize, void* encData, const unsigned int encSize,
void*& decData, unsigned int& decSize)
{
LOG_D(TAG, "decryptData()");
if(encData == nullptr)
{
LOG_E(TAG,"");
return DataEncryption::RESULT_EMPTY_DATA_ERROR;
}
if(encSize == 0)
{
LOG_E(TAG,"");
return DataEncryption::RESULT_SIZE_ZERO_ERROR;
}
IBuffer^ encrypted;
IBuffer^ decrypted;
IBuffer^ iv = nullptr;
String^ algName;
bool cbc = false;
switch (algo)
{
case DataEncryption::ENC_DEFAULT:
algName = "AES_CBC";
cbc = true;
break;
default:
break;
}
SymmetricKeyAlgorithmProvider^ Algorithm = SymmetricKeyAlgorithmProvider::OpenAlgorithm(algName);
IBuffer^ keymaterial = CryptographicBuffer::GenerateRandom((keySize + 7) / 8);
CryptographicKey^ key;
try
{
key = Algorithm->CreateSymmetricKey(keymaterial);
}
catch(InvalidArgumentException^ e)
{
LOG_E(TAG,"encryptData(): Could not create key.");
return DataEncryption::RESULT_ERROR;
}
if (cbc)
iv = CryptographicBuffer::GenerateRandom(Algorithm->BlockLength);
byte *cc = static_cast<byte*>(encData);
IBuffer ^encDataBuffer = byteArrayToIBufferPtr(cc,256);
decrypted = CryptographicEngine::Decrypt(key, encDataBuffer, iv);
byte *bb = IBufferPtrToByteArray(decrypted);
decData = IBufferPtrToByteArray(decrypted);
decSize = decrypted->Length;
return DataEncryption::RESULT_SUCCESS;
}
|
|
|
|
|
You need to provide more information about the problem, what does not work, and which lines of code are giving the problem.
Use the best guess
|
|
|
|
|
Hi Richards,
Thanks for your response. I found the problem. First let me describe the issue: Suppose my source string(say 'pData') is "SampleTextSample" and I encrypt it using encryptData() which stores the encrypted string in 'encryptedData'(suppose). Then I call decryptData() with 'encryptedData' as the input and in turn decryptData() stores the decrypted string in 'decryptedData'(suppose). Now logically, pData and decryptedData should be equal. But this is not happenning in my code.
Error: Using CryptographicBuffer::GenerateRandom() for creating key and initialazation vector in both encryptData() and decryptData(). Thus I am using a different key and initialization vector in encryptData() and another key and initialization vector in decryptData(). Hence the results don't match.
Solution: Arranged to use the same key in both encryptData() and decryptData().
|
|
|
|
|
yourchandrashekhar@gmail.com wrote: and another key and initialization vector in decryptData(). Why would you expect it to work with different keys?
Use the best guess
|
|
|
|
|
I have VisualC++ Ver 5. I know it's old but I have been using it for close to 20 years.
My problem is that when running in debug mode on WinXP VC++ crashes often.
When running on Win2K it runs for hours without problems.
Is there something I should know avout running VC++ on a WinXP computer.
Bob Macklin
Seattle, Wa
|
|
|
|
|
Try to run in Windows 2000 compatibility mode. First thing that comes to mind
|
|
|
|
|
I am using Visual Studio 2008 on a Windows 7 machine to generate a utility to validate TMATS and Chapter 10 file. These are standardized files used in telemetry systems. The files begin with a text based description of the data (7 bit ASCII) followed by large amounts of telemetry data in binary format. The binary data will not be shown, but there are some validation checks to be done.
In the text based preamble there are about ten different major sections, some rather long. Each section describes some aspect of the data. The basic format is an identifier that ends with a colon, followed by text that ends with a semicolon. The next identifier follows.
My plan is a separate dialog or window for each. The user will be able to edit the data and write out to a new file.
I am unsure as to the best solution type. So far I am leaning towards an MFC application with single document support. (Only one file will be open for reading only, and a new file optionally opened for writing.) The next best option seems to be with Dialog support. Or maybe someone will suggest something else completely.
This will be open source code posted on my web site for others in the telemetry industry to use and comment on. I plan to make all the classes and code as simple as I can so it can be ported to other systems. But I will not go to extreme lengths for portability.
I am fairly good at writing code, but on the lower end of intermediate for Visual Studio.
Pleas make your suggestions.
Thanks for your time
If you work with telemetry, please check this bulletin board: http://www.bkelly.ws/irig_106/
|
|
|
|
|