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
============================================================
#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::Runtime::InteropServices;
[DllImport("kernel32.dll", CharSet=System::Runtime::InteropServices::CharSet::Auto)]
int FormatMessage(int dwFlags,
IntPtr *lpSource,
int dwMessageId,
StringBuilder lpBuffer,
int dwLanguageId,
int nSize,
IntPtr *Arguments);
// Constructor
manageDateFile::manageDateFile(bool _fDebug){
fDebug = _fDebug;
}
// Show the mesage for last Error error
void manageDateFile::showLE(String^ lpszFunction, DWORD dw)
{
// 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
/*
// Display the error message
// Manage
String^ dispMsg;
StringCchPrintf((LPTSTR)lpDisplayBuf,
LocalSize(lpDisplayBuf) / sizeof(TCHAR),
TEXT("%s failed with error %d: %s"),
lpszFunction, dw, lpMsgBuf);
Debug::WriteLine((LPCTSTR)lpDisplayBuf);
LocalFree(lpMsgBuf);
*/
}
============================================================
Avez vous un exemple qui fonctionne?
Merci par avance.