cs_sphinx2
Messages postés2Date d'inscriptionlundi 25 juillet 2005StatutMembreDernière intervention 8 juin 2009
-
5 juin 2009 à 14:04
cs_sphinx2
Messages postés2Date d'inscriptionlundi 25 juillet 2005StatutMembreDernière intervention 8 juin 2009
-
8 juin 2009 à 07:39
Bonjour,
J'essaie d'appeler FormatMessage sous visual studio C++ 2008 en Windows forms donc en C++ "managé".
Mon code est celui-c mais ne compile pas: voir Error dans les commentaires du code
==========================================================
// Retrieve the system error messa ge for the last-error code
int messageSize = 255;
String^ lpMsgBuf = "";
int dwFlags = FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS;
IntPtr ptrlpSource = IntPtr::Zero;
IntPtr prtArguments = IntPtr::Zero;
int retVal = FormatMessage(
dwFlags,
&ptrlpSource,
dw,
0,
&lpMsgBuf,
messageSize,
&prtArguments); //<-----Error 1 error C2665:
'FormatMessage' : none of the 2 overloads could convert all the
argument types v:\dev\cpp\ChgDate\ChgDate\manageDateFile.cpp 48 ChgDate
cs_sphinx2
Messages postés2Date d'inscriptionlundi 25 juillet 2005StatutMembreDernière intervention 8 juin 2009 8 juin 2009 à 07:39
Bonjour,
J'ai finalement trouvé une solution
La voici:
#include "StdAfx.h"
#include <windows.h>
#include <tchar.h>
#include <strsafe.h>
#include "Constants.h"
#include "manageDateFile.h"
#using <mscorlib.dll>
#using <System.dll>
using namespace System::Diagnostics ;
using namespace System::Text;
using namespace System::Collections;
using namespace System;
using namespace System::Runtime::InteropServices;
// Fonctionne
[DllImport("kernel32.dll", CharSet=System::Runtime::InteropServices::CharSet::Auto)]
int LocalFree(System::IntPtr
);
[DllImport("user32.dll", CharSet=System::Runtime::InteropServices::CharSet::Auto)]
int MessageBox(IntPtr, StringBuilder^ text, String^ caption, unsigned int type);
[DllImport("kernel32.dll", CharSet=System::Runtime::InteropServices::CharSet::Auto)]
int FormatMessage(
int dwFlags,
System::IntPtr* lpSource,
int dwMessageId,
int dwLanguageId,
System::IntPtr* lpMsgBuf,
int nSize,
System::IntPtr);
// Constructor
manageDateFile::manageDateFile(bool _fDebug){
fDebug = _fDebug;
}
// Show the mesage for last Error error
void manageDateFile::showLE(String^ myMessage, DWORD dw)
{
// Retrieve the system error message for the last-error code
IntPtr lpMsgBuf = IntPtr::Zero;
IntPtr ptrlpSource = IntPtr::Zero;
StringBuilder^ text = gcnew StringBuilder;
int retVal = FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
&ptrlpSource,
dw, // Message ID
MAKELANGID(LANG_NEUTRAL,SUBLANG_NEUTRAL), // LANG
&lpMsgBuf,
255,
IntPtr::Zero); // &prtArguments);
String^ textMsg =System::Runtime::InteropServices::Marshal::PtrToStringAuto(lpMsgBuf); text->AppendFormat("sys message {0}, Code {1}, in {2]", textMsg, dw, myMessage);
MessageBox(IntPtr::Zero, text, "SYSTEM ERROR", 1);
// Free the pointer
LocalFree(lpMsgBuf);
}