|
Alexander,
As I said in my email, I am trying to export two C++ objects -- not a simple integer. Do you still recommend a defs file? In addition, I have a few C++ base-class declarations and a few global C++ functions that I am also exporting. I would expect putting these in a defs file would not be as straight forward. Can you mix a defs file for data with __declspec for classes and functions all within the same DLL?
Thanks much,
Matt
P.S., what is the significance of the superscript M. in your login?
|
|
|
|
|
.
hello , i have used a class CPicture (obtained from this site itself) to load a jpeg image from the resource..now the problem is if i have to reload another image in the same sapce i have to unload the previous image....how do i do that????
Any kind of help is appreciated.
Thanking you.
Satadru
|
|
|
|
|
i hope u don#t want to unload the picture u just override the picture by calling the loadpicture function and replace the piecture in the same place.
Shanmuga Sundar.V
|
|
|
|
|
MY DLL CODE : CDBMgrClass is a generic class got added to the
DLL workspace for IGenericDBManager Interface.
I am calling my interface standard method i.e. STDMETHODIMP CGenericDBManager::Fetch(BSTR bstrSELECTSQLString, _Recordset **pFetchRecordset, BSTR *bstrFetchErrDesc, LPDISPATCH *ppVal)
from my stub in VC++(MFC). But the stub returns the OxThe thread 0x388 has exited with code 0 (0x0).
First-chance exception in GH_DBM_COMDLL_Stub_MFC_EXE.exe: 0xC0000005: Access Violation.
First-chance exception in GH_DBM_COMDLL_Stub_MFC_EXE.exe: 0xC0000005: Access Violation.
Below the DLL code : The STDMETHODIMP calls internally CDBMgrClass::ExecuteFetchQuery()
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Function Name : ExecuteFetchQuery()
// Description : It does the EXECUTE of the FETCH SQL COMMAND
// Return Value : _RecordsetPtr
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
_RecordsetPtr CDBMgrClass::ExecuteFetchQuery(char* sqlstring)
{
HRESULT hr = S_OK;
try
{
IsConnected();
m_csDatabaseOpLock.Lock();
TESTHR(m_pCommand.CreateInstance(__uuidof(Command)));
TESTHR(m_pRecordset.CreateInstance(__uuidof(Recordset)));
TESTHR(m_pParameter.CreateInstance(__uuidof(Parameter)));
m_pCommand->ActiveConnection = m_pConnObj;
m_pCommand->CommandText = sqlstring;
m_pCommand->CommandType = adCmdText;
m_pRecordset = m_pCommand->Execute(NULL, NULL, adCmdText);
m_pConnObj->Close();
}
catch(CException exception)
{
// Handle the exception here.
// "exception" contains information about the MFC DB exception.
TCHAR szCause[255];
EString strFormatted;
exception.GetErrorMessage(szCause, 255);
strFormatted = _T("The Error: ");
strFormatted += szCause;
OutputDebugString(strFormatted.c_str());
m_bIsConnected = FAILURE;
m_pRecordset = NULL;
}
catch(_com_error &e)
{
hr = e.Error();
_bstr_t bstrError = e.Description();
OutputDebugString(bstrError);
m_bIsConnected = FAILURE;
m_pRecordset = NULL;
}
catch(...)
{
}
m_csDatabaseOpLock.Unlock();
return m_pRecordset;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Function Name : Fetch
// Description : Interface Public Method
// Input : /*[in]*/BSTR bstrSELECTSQLString
// Output : /*[out]*/_Recordset **pFetchRecordset, /*[out]*/BSTR *bstrFetchErrDesc,/*[out]*/LPDISPATCH *ppVal
// Return Value : S_OK or E_FAIL
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
STDMETHODIMP CGenericDBManager::Fetch(BSTR bstrSELECTSQLString, _Recordset **pFetchRecordset, BSTR *bstrFetchErrDesc, LPDISPATCH *ppVal)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
USES_CONVERSION;
CoInitialize(NULL);
HRESULT hr = S_OK;
CDBMgrClass* pDBMgrClass = NULL;
_RecordsetPtr m_pRecord_Set(__uuidof(Recordset));
m_pRecord_Set = NULL;
pFetchRecordset = NULL;
try
{
pDBMgrClass = new CDBMgrClass();
if(pDBMgrClass)
{
_bstr_t _bstrFetchQuery(bstrSELECTSQLString);
m_pRecord_Set = pDBMgrClass->ExecuteFetchQuery(_bstrFetchQuery.operator char*());
if(m_pRecord_Set)
*pFetchRecordset = m_pRecord_Set;
m_pRecord_Set->QueryInterface(IID_IDispatch,(void**) &ppVal);
m_pRecord_Set->Close();
}
else
{
EString strFormatted;
strFormatted = _T("\nGHDER Database Fetch Error\n");
_bstr_t _bstrFetchErrorString(_T(strFormatted.c_str()));
*bstrFetchErrDesc = _bstrFetchErrorString.operator wchar_t*();
delete pDBMgrClass;
}
// Clean up objects before exit
bstrFetchErrDesc = NULL;
delete pDBMgrClass;
}
catch(CException exception)
{
// Handle the exception here.
// "exception" contains information about the MFC DB exception.
TCHAR szCause[255];
EString strFormatted;
exception.GetErrorMessage(szCause, 255);
strFormatted = _T("The Error: ");
strFormatted += szCause;
_bstr_t _bstrFetchErrorString(_T(strFormatted.c_str()));
*bstrFetchErrDesc = _bstrFetchErrorString.operator wchar_t*();
delete pDBMgrClass;
hr = E_FAIL;
}
catch ( _com_error &e )
{
_bstr_t bstrError = e.Description();
_variant_t tErr(e.Error());
_bstr_t tMsg("IGenericDBManager::Fetch::=" );
tMsg += "::Error::";
tMsg += (_bstr_t) tErr;
*bstrFetchErrDesc = tMsg.operator wchar_t*();
delete pDBMgrClass;
hr = E_FAIL;
}
catch(...)
{
}
CoUninitialize();
return hr;
}
///////////////////////////////////////////////////////////////////////
STUB CALLER>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//////////////////////////////////////////////////////////////////////
void CGH_DBM_COMDLL_Stub_MFC_EXEDlg::OnFetch()
{
HRESULT hr = S_OK;
USES_CONVERSION;
BSTR *pbstrFetchErrString = NULL;
_RecordsetPtr pRecordset = NULL;
IGenericDBManager *pGenericDBManager = NULL;
BSTR bstrSELECTSQLQuery;
//FORM THE SQL QUERY FOR ANY TABLE
_bstr_t _bstrSELECTSQLString = (_T("SELECT * FROM GHDR1TS_HAZARDOUS_COMMODITY"));
bstrSELECTSQLQuery = _bstrSELECTSQLString.operator wchar_t*();
//END QUERY
pRecordset.CreateInstance(__uuidof(Recordset));
//Initialize the COM library
CoInitialize(NULL);
//Instantiate the COM object for the interface i.e. IDBM_ComDll
hr = CoCreateInstance(CLSID_GenericDBManager, NULL, CLSCTX_INPROC_SERVER,
IID_IGenericDBManager, (void **) &pGenericDBManager);
if (FAILED(hr))
{
MessageBox("\nIGenericDBManager Interface not instantiated\n", NULL, MB_OK);
return;
}
else
{
MessageBox("\nIGenericDBManager Interface instantiated\n", NULL, MB_OK);
VARIANT* pvntDB_Connect_Status = NULL;
BSTR* pbstrConnectErrString = NULL;
hr = pGenericDBManager->Connect((VARIANT*) &pvntDB_Connect_Status, pbstrConnectErrString);
if (SUCCEEDED(hr))
{
hr = pGenericDBManager->Fetch(bstrSELECTSQLQuery, &pRecordset, pbstrFetchErrString);
if (FAILED(hr))
{
MessageBox("\nIGenericDBManager::Fetch() failed\n", NULL, MB_OK);
return;
}
else
{
VARIANT* pConnection = NULL;
VARIANT* pTable = NULL;
_bstr_t _bstrTable(_T("GHDR1TS_HAZARDOUS_COMMODITY"));
_variant_t _vtTable(_bstrTable.operator const wchar_t *());
hr = pRecordset->get_ActiveConnection((VARIANT*) &pConnection);
_variant_t _vtConnection(*pConnection,true);
hr = pRecordset->Open( _vtTable.Detach(), _vtConnection.Detach(),adOpenKeyset,adLockOptimistic,adCmdText);
if(pRecordset != NULL)
{
int nRecordCount = pRecordset->RecordCount;
int nMaxRecords = pRecordset->MaxRecords;
int nFieldCount = pRecordset->Fields->Count;
MessageBox((LPCTSTR) nRecordCount, NULL, MB_OK );
MessageBox((LPCTSTR) nMaxRecords, NULL, MB_OK );
pRecordset->MoveFirst();
for (int i = 0; i< nRecordCount; nRecordCount++)
{
for(int j=0; j< nFieldCount; j++)
{
MessageBox((LPCTSTR)pRecordset->Fields->GetItem("IMO")->Value.bstrVal, NULL, MB_OK);
}
pRecordset->MoveNext();
}
pRecordset->Close();
}
else
{
MessageBox("NULL RECORDSET", NULL, MB_OK);
pRecordset->Close();
}
}
}
else
{
MessageBox("CONNECT FAILURE", NULL, MB_OK);
}
}
//Uninitialize the COM library
CoUninitialize();
}
/
|
|
|
|
|
This line's very suspicious:
*bstrFetchErrDesc = _bstrFetchErrorString.operator wchar_t*(); You're trying to assign a non-prefixed string to a variable that the caller expects will contain a BSTR. I think you're trying to stop your local _bstr_t object from freeing the encapsulated BSTR when it goes out of scope. The _bstr_t class does not have any way to do this (in Visual C++ 6.0); I recommend using ATL's CComBSTR instead, using its Detach method once you've assigned to *bstrFetchErrDesc .
You should also be aware that MFC overrides the global operator new , replacing it with a version that throws a CMemoryException when the allocation fails. It does not return NULL .
|
|
|
|
|
Hi there
I would just like to know how do i write a programme
that would take an error code as a argument and display
the error message thats associated with the error code
Example: ERROR CODE 00300
Print : Bad IP Checksum
How and in what should i store the list of errors
How do i iterate\scan thru the list get the error code
and print the error message.
Can i store both in one file?
|
|
|
|
|
Have you looked at FormatMessage() ?
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
could u please use a topic that describes the problem?
Don't try it, just do it!
|
|
|
|
|
Hi,
I know it is possible to hook a function which is exported in a dll, but I was wondering if it is possible to hook a function in an exe?
thanx
Don't think you are, know you are...
|
|
|
|
|
Do you have the source of that exe?
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Yes, I do have the source of that exe.
What I would like to do is make some sort of program that hooks several functions of the specific exe so I can extract internal information.
We have lots of version of this exe and we can't put lots of debugging information in them...
Don't think you are, know you are...
|
|
|
|
|
-You can export these functions from the exe
or
-Call a common function that is exported into the dll and giving you the amount of info you need
Or Make own your own debugging thread and check the CreateRemoteThread family API
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
The problem is that I can't modify the sources of the original exe.
That's why I was wondering if it is possible the hook an 'internal' function, given that you know the name of it (if this is even relevant).
Don't think you are, know you are...
|
|
|
|
|
In fact it is, but its a delicate process.
Saying you have several versions of the exe, so a reverse engineering method (patching and calling a code from an exe) is somehow difficult or even not feasible if you dont want to modify the code
So a CreateRemoteThread is a better way to deal with this problem, with a Stack handling method in order to see what function is being called so you dump its parameters
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
I'll have a look at the CreateRemoteThread thingy...
Thanx
Don't think you are, know you are...
|
|
|
|
|
everything is possible!
tell me what's ur software's purpose and i'll tell u how to do it.
Don't try it, just do it!
|
|
|
|
|
Hi!
I'm have some problems with atoi. My simple program reading numbers from a file into a buffer. The numbers represent the time of the day with microseconds precision.
Ex. 124831123456
124831234567
Then will I subtract them but it will not work? Can someone help me?
int line;
int t, t1, t2;
char buffer[ROW][Buffer_Size];
ifstream inFile;
char inputFilename;
for(int k=0; k<20; k++){
inFile.getline(buffer[k], TIME_SIZE);
}
for(int x=1; x<20; x++){
t2 = atoi(buffer[x]);
t1 = atoi(buffer[x-1]);
t = t2 -t1;
cout << "t is equal to " <
|
|
|
|
|
124831123456 is too big to fit in a int
try atof and fill it into a float or check strtol
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
|
Hi,
What is the difference between BOOL and bool??
Best Regards,
A.Ilamparithi
|
|
|
|
|
This topic is already discussed.
Quick info:
BOOL is a int ( integer value from 0 to 65535 )
bool is a boolean ( true false )
but BOOL can be used as bool ( BOOL bBoolean = TRUE or BOOL bBoolean = FALSE )
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
BOOL goes back to the days when bool was not part of the C++ standard.
It is typedef'ed as an int, where FALSE is 0.
bool, however is inherently c++. Although BOOL and bool may be used interchangeably, you should be very aware of the dangers involved in mixing these two types.
There were a few discussions about this on the lounge a while ago I think. There may be an FAQ article about this as well. Have a search on it. It is worth knowing.
I Dream of Absolute Zero
|
|
|
|
|
If I remember it corectly it's: "enum and #define" - bool is a enum and the classic BOOL is #define'd
Regards,
Michael Mogensen, mm it-consult dk.
><((((º> ·.¸¸.· ><((((º> ·.¸¸.· ><((((º>
|
|
|
|
|
Hi
I create an application which able to print any documents.
This bit of my code
...
//Create printer DC m_prtDC
...
//All fine ,now create compatible DC (m_extDC)
//with one ,which has same size
...
//All fine, set neccessary font size and print text
//into m_extDC
...
//Now try to print this text
m_prtDC.StartDoc(LPCTSTR("MyDoc"));
m_prtDC.StartPage();
//Copy from dc, where allocated my text to printer dc
//2400 & 3600 my printer DC size
m_prtDC.BitBlt(0,0,2400,3600,&m_extDC,0,0,SRCCOPY);
m_prtDC.EndPage();
m_prtDC.EndDoc();
When my printed text (printed with TextOut() fun)not enought big all printed fine.But when m_extDC hold a lot of text ,printer wan't to printed one.I watch what priner are prepared to printing (respected sensor are flick), but from any time error sensor are switched on, and all halt.At that
all invoked routines returned sucessfull.
Where is my fault, and how i can to solve it.
Thank.
|
|
|
|
|
BitBlt() is usually not supported or incorrectly supported on most printer drivers (DC). If your printing in MFC make use of the standard MFC printing architecture. If not, take alook at Chris Maunders article "Printing wiuthout the Doc/view architecture" in the printing section. Also my article "Printing tips n Tricks from the Trenches" should be of use.
Roger Allen - Sonork 100.10016
If your dead and reading this, then you have no life!
|
|
|
|