|
I certainly am using #import. Is this known to cause a problem like this?
Thanks for the binary comparing info.
ns
|
|
|
|
|
Instead of a debug exe build a release exe and take it home and run it. If it works then you are OK. If it does not, then you need to worry about the DLLs your exe is using and various dependency and version issues. It should not happen but yo never know.
|
|
|
|
|
Does it also crash if you start the exe or just when started from the IDE ?
It could be differences in the MFC dll's or something like that(?). If so you could use static linking so the exe would run on any version.
Check for compiler warnings.
Good luck
Rutger
|
|
|
|
|
Isnt it a fact that you can only choose static or dynamic linking at the very start of the program? Can you switch at this stage (midway), How do you do that? I saw such an option when I created the app using the appwizard.
Thanks so much,
ns
|
|
|
|
|
ns wrote:
snt it a fact that you can only choose static or dynamic linking at the very start of the program? Can you switch at this stage (midway), How do you do that? I saw such an option when I created the app using the appwizard.
Thanks so much,
You can change it if you go to Project->settings (or press <ALT>+F7) then you will see the general tab where you can select how to use the MFC (options are not at all, shared or static)
Regards
Rutger
|
|
|
|
|
It happened to me too and I finally found the reason: if one of your machines has "Microsoft .NET platform" installed and the other doesn't, the problem arises. Then I completely removed .NET from my machine and the problem is gone.
I'm not sure if this solves your problem but that's how I solved mine.
|
|
|
|
|
well, I did install the .net beta last year. Maybe some residual side effect. Thanks,
ns
So I should build on my XP which has never met .net...hopefully that will be okay.
|
|
|
|
|
Hi,
I was playing around a little with .Net, just for fun and created a dialog based project. I added a button to my dialog and created an OnBnClickedButton1() function. But I tried to make this function return a BOOL rather than being void.
I then get the following error message:
error C2440: static_cast: cannot convert from BOOL(__thiscall CSampleDlg::*)(void) to AFX_PMSG.
Anyone can explain to me how does one make this function return something. Or is it not allowed in .Net?
Thanks
Regards
Rui
|
|
|
|
|
VC.NET has improved type checking in message maps. The header of your function is simply not compatible with ON_CONTROL event handler.
Anyway, it's MFC who calls your handler - so return value is ignored.
Tomasz Sowinski -- http://www.shooltz.com
"Yields falsehood when preceded by its quotation" yields falsehood when preceded by its quotation.
|
|
|
|
|
Modifying signature of message handlers were never recommended...
|
|
|
|
|
I'm truing to make cd-label app, so...
How can i add text, from textbox, into bitmap and save them together in bmp, or jpg?
|
|
|
|
|
|
Hi there !
My problem is as follows:
I have a CFtpConnection and there are some cases, that it is blocking.
I already put it into a thread, everything is working good, but: When it blocks, how can i kill it (like TerminateThread() , but this is not cleaning up...)
Thanx in advance!
Olli
I feel like I'm diagonally parked in a parallel universe.....
|
|
|
|
|
I would recommend to use async monikers instead of MFC classes such like CFtpConnection and so on.
In a previous project, I just derived my class from IBindStatusCallback and implemented a few methods required for data transfer. The good news is that I could stop the transfer at any moment properly, hence achieving what you are looking for.
Below is a sample code that did a http://... file transfer :
class CXmlInternetFileManager : public CXmlFileManager, public IBindStatusCallback
{
protected:
long m_cRef;
char m_szProxy[MAX_PATH];
int m_nProxyPort;
IBinding* m_pBinding;
IStream* m_pStream;
HWND m_hwndStatus;
FILE *m_tmpFile;
BOOL m_bStop_EvrythingIsReceived;
DWORD m_dwLoadedSoFar;
DWORD m_dwOffsetReadByClient;
public:
CXmlInternetFileManager();
virtual ~CXmlInternetFileManager();
virtual BOOL Open(char *szURL);
virtual BOOL Read(char *szInputBuffer, int nMaxLength, int &nActualLength);
virtual BOOL Close();
public:
virtual HRESULT __stdcall QueryInterface(const IID& iid, void** ppv) ;
virtual ULONG __stdcall AddRef() ;
virtual ULONG __stdcall Release() ;
virtual HRESULT STDMETHODCALLTYPE OnStartBinding(
DWORD dwReserved,
IBinding __RPC_FAR *pib);
virtual HRESULT STDMETHODCALLTYPE GetPriority(
LONG __RPC_FAR *pnPriority);
virtual HRESULT STDMETHODCALLTYPE OnLowResource(
DWORD reserved);
virtual HRESULT STDMETHODCALLTYPE OnProgress(
ULONG ulProgress,
ULONG ulProgressMax,
ULONG ulStatusCode,
LPCWSTR szStatusText);
virtual HRESULT STDMETHODCALLTYPE OnStopBinding(
HRESULT hresult,
LPCWSTR szError);
virtual HRESULT STDMETHODCALLTYPE GetBindInfo(
DWORD __RPC_FAR *grfBINDF,
BINDINFO __RPC_FAR *pbindinfo);
virtual HRESULT STDMETHODCALLTYPE OnDataAvailable(
DWORD grfBSCF,
DWORD dwSize,
FORMATETC __RPC_FAR *pformatetc,
STGMEDIUM __RPC_FAR *pstgmed);
virtual HRESULT STDMETHODCALLTYPE OnObjectAvailable(
REFIID riid,
IUnknown __RPC_FAR *punk);
private:
CXmlInternetFileManager& operator=(const CXmlInternetFileManager &obj);
};
#include "stdafx.h"
#include "XmlFileManager.h"
CXmlInternetFileManager::CXmlInternetFileManager() : m_cRef(0)
{
}
CXmlInternetFileManager::~CXmlInternetFileManager()
{
Close();
}
CXmlInternetFileManager& CXmlInternetFileManager::operator=(const CXmlInternetFileManager &obj)
{
return *this;
}
HRESULT CXmlInternetFileManager::QueryInterface(const IID& iid, void** ppv)
{
if (iid == IID_IUnknown)
{
*ppv = static_cast<IBindStatusCallback*>(this) ;
}
else if (iid == IID_IBindStatusCallback)
{
*ppv = static_cast<IBindStatusCallback*>(this) ;
}
else
{
*ppv = NULL ;
return E_NOINTERFACE;
}
reinterpret_cast<IUnknown*>(*ppv)->AddRef() ;
return S_OK ;
}
ULONG CXmlInternetFileManager::AddRef()
{
return InterlockedIncrement(&m_cRef) ;
}
ULONG CXmlInternetFileManager::Release()
{
if (InterlockedDecrement(&m_cRef) == 0)
{
delete this ;
return 0 ;
}
return m_cRef ;
}
BOOL CXmlInternetFileManager::Open(char *szURL)
{
HRESULT hr;
if (!szURL || strlen(szURL)==0)
return FALSE;
m_dwLoadedSoFar=0;
m_dwOffsetReadByClient=0;
m_bStop_EvrythingIsReceived = FALSE;
strcpy(m_szURL, szURL);
m_tmpFile = fopen("c:\\test.txt","w+b");
IBindCtx *pbc=NULL;
hr = CreateAsyncBindCtx(0, this , NULL, &pbc);
if (FAILED(hr))
return FALSE;
IMoniker *pmk=NULL;
WCHAR *swzURL = new WCHAR[strlen(szURL)+1];
::MultiByteToWideChar(CP_ACP, 0, szURL, -1, swzURL, strlen(szURL)+1);
hr = CreateURLMoniker(NULL, swzURL, &pmk);
if (FAILED(hr))
return FALSE;
hr = pbc->RegisterObjectParam(SZ_ASYNC_CALLEE, pmk);
if (FAILED(hr))
return FALSE;
IStream* pStream;
hr = pmk->BindToStorage(pbc, NULL, IID_IStream, (void**) &pStream);
if (FAILED(hr))
return FALSE;
delete [] swzURL;
return TRUE;
}
BOOL CXmlInternetFileManager::Read(char *szInputBuffer, int nMaxLength, int &nActualLength)
{
while(1)
{
peekMessage();
nActualLength = 0;
if ( m_dwOffsetReadByClient < m_dwLoadedSoFar)
{
long nAvailable = m_dwLoadedSoFar - m_dwOffsetReadByClient;
if (nAvailable>nMaxLength-1)
nAvailable = nMaxLength-1;
fseek(m_tmpFile,m_dwOffsetReadByClient,SEEK_SET);
nActualLength = fread(szInputBuffer, 1, nAvailable, m_tmpFile);
szInputBuffer[nActualLength]='\0';
m_dwOffsetReadByClient += nAvailable;
return TRUE;
}
if (m_bStop_EvrythingIsReceived)
return TRUE;
}
}
BOOL CXmlInternetFileManager::Close()
{
if (m_tmpFile)
{
fclose(m_tmpFile);
m_tmpFile=NULL;
}
return TRUE;
}
HRESULT STDMETHODCALLTYPE CXmlInternetFileManager::OnStartBinding(
DWORD dwReserved,
IBinding __RPC_FAR *pib)
{
m_pBinding = pib;
m_pBinding->AddRef();
m_pStream = NULL;
return S_OK;
}
HRESULT STDMETHODCALLTYPE CXmlInternetFileManager::GetPriority(
LONG __RPC_FAR *pnPriority)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE CXmlInternetFileManager::OnLowResource(
DWORD reserved)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE CXmlInternetFileManager::OnProgress(
ULONG ulProgress,
ULONG ulProgressMax,
ULONG ulStatusCode,
LPCWSTR szStatusText)
{
return(NOERROR);
}
HRESULT STDMETHODCALLTYPE CXmlInternetFileManager::OnStopBinding(
HRESULT hresult,
LPCWSTR szError)
{
m_pBinding->Release();
m_pBinding = NULL;
m_pStream = NULL;
m_bStop_EvrythingIsReceived = TRUE;
return S_OK;
}
HRESULT STDMETHODCALLTYPE CXmlInternetFileManager::GetBindInfo(
DWORD __RPC_FAR *grfBINDF,
BINDINFO __RPC_FAR *pbindinfo)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE CXmlInternetFileManager::OnDataAvailable(
DWORD grfBSCF,
DWORD dwSize,
FORMATETC __RPC_FAR *pformatetc,
STGMEDIUM __RPC_FAR *pstgmed)
{
if (m_pStream==NULL)
m_pStream = (IStream*) pstgmed->pstm;
if (0)
{
m_pBinding->Abort();
}
else
{
if (dwSize > m_dwLoadedSoFar)
{
DWORD dwRead = dwSize - m_dwLoadedSoFar;
DWORD dwActuallyRead;
char *buf = new char[dwRead];
m_pStream->Read(buf, dwRead, &dwActuallyRead);
fseek(m_tmpFile,0,SEEK_END);
fwrite(buf,1,dwActuallyRead,m_tmpFile);
delete buf;
m_dwLoadedSoFar = dwSize;
}
}
return S_OK;
}
HRESULT STDMETHODCALLTYPE CXmlInternetFileManager::OnObjectAvailable(
REFIID riid,
IUnknown __RPC_FAR *punk)
{
return S_OK;
}
And I swallow a small raisin.
|
|
|
|
|
Hi Stephane!
First of all, thanx for your answer! This piece of code is looking awsome.... I'm not really new to VC and MFC, but this is for a short overlook really heavy...
Maybe it would be possible to give me a smaller example to get a quick look behind the main points?? This would be great!
Thanx,
Olli
Olli
I feel like I'm diagonally parked in a parallel universe.....
|
|
|
|
|
how to get point(x,y) where mouse click on desktop window
how to capture mouse events which will tell its position ,what button click etc.
is there any interrupt service of mouse where we can write our procedure ? to get mouse event info?
same for keborad ?
r00d0034@yahoo.com
|
|
|
|
|
You'll need a global hook. Check the docs for SetWindowsHookEx.
Tomasz Sowinski -- http://www.shooltz.com
"Yields falsehood when preceded by its quotation" yields falsehood when preceded by its quotation.
|
|
|
|
|
can u give me helping meterial related to
SetWindowsHookEx.
or any link that could solve mine problem
r00d0034@yahoo.com
|
|
|
|
|
|
please read that code and solve mine problem
tmpProcess = new Process();
tmpProcess.WaitForInputIdle();
tmpProcess.StartInfo.FileName="f:\\mirc59t";
try{
tmpProcess.Start();
while(! tmpProcess.Responding)System.Windows.Forms.Application.DoEvents();
}catch{}
tmpProcess.WaitForInputIdle();
IntPtr hWnd=tmpProcess.MainWindowHandle;
Srm=new send_recive_messages(hWnd);
/*/////////////////////////////////////////////////////
managed public __gc class send_recive_messages constructor
////////////////////////////////////////////////////*/
send_recive_messages::send_recive_messages(IntPtr par_hwnd)
{
hwnd=(HWND)par_hwnd.ToInt64();
TCHAR szBuffer[256],szBuffer1[256];
::GetWindowText(hwnd, szBuffer, sizeof(szBuffer) / sizeof(TCHAR));
::GetClassName(hwnd, szBuffer1, sizeof(szBuffer1) / sizeof(TCHAR));
//////////////////////////////////////////////////////////
HWND h=::FindWindowEx(hwnd,0,szBuffer1,szBuffer);
//////////////////////////////////////////////////////////
}//code finish herer
///////////////////////////////////////////
h variable recive zero that's why remaining code could not run.
it should not recive zero because the process main window
contain two button and four Static members.
can any body tell why it recive 0?
and what i have to do so that it should not recive zero?
r00d0034@yahoo.com
|
|
|
|
|
Maybe calling GetLastError() after FindWindowEx() might shed some light on things?
Cheers,
Fredrik
<right>Sonork ID: 100.11430:PhatBoy
"Felix qui potuit rerum cognoscere causas."
|
|
|
|
|
FindWindowEx needs the caption/class of the child window. You're passing caption/class of main window.
Tomasz Sowinski -- http://www.shooltz.com
Never argue with an idiot, he'll bring you to his level and beat you with experience.
|
|
|
|
|
FindWindowEx needs the caption/class of the child window. You're passing caption/class of main window.
how to get that caption class plz help me.
r00d0034@yahoo.com
|
|
|
|
|
Can't you just use GetDlgItem? You know the IDs of child windows, don't you?
Tomasz Sowinski -- http://www.shooltz.com
"Yields falsehood when preceded by its quotation" yields falsehood when preceded by its quotation.
|
|
|
|
|
Hey Guys
I have a CView dirived class i am using as my main view in an MDI application and i have a CWnd derived class which is a control i am writing how do i get the control to be drawn inside the CView Class i have tried BeginPaint and Print with no luck. At the moment i create the control in the create part of the CView and then check for a safe handle in the paint of teh cview before calling BeginPaint of the control which doesn't work.
Cheers Peter
|
|
|
|