|
Hi Maximilien,
Thanx for your reply,
I just want to ask can I use some kind of syncronization mechanism, as after taking reference to the image loaded with FreeImage, I am applying the effcet using Magick++. its done.
I have one dialog Box (called A) on which Image is loaded using FreeImage. I'll invoke a dialog box ( called B) which has one slider control. After changing the position of the slider control, I am passing the value of slider control to parent dialog box. That effect gets applied to the image but Image gets saved to memory location. Again I'll load the Image with FreeImage.
I want before saving the Image, the effect should be visible on the Image, I want when the user drags the slider control, at the same time, value should get passed to the another dialog.
Apologize if content is not understood.
Please let me know if u need any further clarification.
Please let me know if anybody have any idea.?
Regards,
mbatra
|
|
|
|
|
I want to export some functions with Dll.
The Source File:
void Fun(std::wstring)
{
}
The def file:
LIBRARY Standby
EXPORTS
Fun
But when I load the dll with
LoadLibary , I get STL crash message.
When I switch the parameter type to basic
C types: such as
int ,
char ,
int* . Everything is OK.
I wonder whether can I use STL param type in Dll.
Any one can help me?
|
|
|
|
|
See, for instance, here[^].
Veni, vidi, vici.
|
|
|
|
|
Falconapollo wrote: I get STL crash message. Please don't assume that we can guess which message you are talking about. Unless you give the exact details of the message, and the line of code that caused the error it's impossible to give any useful suggestions.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
hi all,
i m using IPreviewHandlerto create preview of diffrent type of files,but some application stop working and give a crash message with Event Name : BEX,
IPreviewHandler *pHandle;
IInitializeWithFile *m_IFile;
IInitializeWithStream *m_IStream;
IStream *pStream;
if(pHandle != NULL)
{
if(m_IFile!=NULL)
{
m_IFile->Release();
m_IFile = NULL;
}
if(m_IStream!=NULL)
{
m_IStream->Release();
m_IStream = NULL;
}
if(m_pStream != NULL)
{
m_pStream->Release();
m_pStream = NULL;
}
pHandle->Unload();
pHandle->Release();
pHandle = NULL;
CoUninitialize();
}
HRESULT hres;
WCHAR *pwcExtn = NULL;
CString csClsid;
pwcExtn = StrRChr(szFile, NULL, L'.');
csClsid = GetClsidFromExtn( pwcExtn );
CLSID cls;
pHandle = NULL;
m_IFile = NULL;
m_IStream = NULL;
pStream = NULL;
if(CLSIDFromString( (LPWSTR)(LPCTSTR)csClsid,&cls) != NOERROR )
{
return 0;
}
else
{
CoInitialize(NULL);
hres = CoCreateInstance(
cls,
0,
CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER,
IID_IPreviewHandler,(LPVOID*)&pHandle);
if (FAILED(hres))
{
CoUninitialize();
return 0;
}
hres = pHandle->QueryInterface(IID_IInitializeWithFile,(LPVOID*)&m_IFile );
if (FAILED(hres))
{
hres = pHandle->QueryInterface(IID_IInitializeWithStream,(LPVOID*)&m_IStream );
if (FAILED(hres))
{
CoUninitialize();
return 0;
}
if(CreateStreamOnHGlobal(NULL, TRUE, &pStream) == S_OK)
{
CFileException pError ;
CFile picFile;
if(picFile.Open(szFile, CFile::modeRead | CFile::typeBinary,&pError))
{
BYTE pBuffer[1024];
UINT uiRead = 0;
while((uiRead = picFile.Read(pBuffer, sizeof(pBuffer))) != 0)
{
ULONG ulWritten = 0;
pStream->Write(pBuffer, uiRead, &ulWritten);
}
picFile.Close();
}
else
{
TCHAR szError[1024];
pError.GetErrorMessage(szError, 1024);
AfxMessageBox(szError);
}
}
m_IStream->Initialize(pStream,STGM_READ);
}
else
hres = m_IFile->Initialize(szFile,STGM_READ);
hres = pHandle->SetWindow( hWnd , &rectPreview );
pHandle->DoPreview();
pHandle->SetRect(&rectPreview);
}
i really dont understand whats happning here.
please help me for this.
|
|
|
|
|
Hoping to get some help from the experts here. I have a service, "Listener", that is listing on 0.0.0.0:7070. I have another application, "Agent" that receives fully-formed UDP/IP packets via a proprietary interface.
I would like to preserve the UDP/IP packet in its entirety (do not want to perform any NAT) and somehow get it from the Agent to the Listener.
Current setup:
Physical NIC with address 10.80.8.10 / 255.255.0.0
Microsoft Loopback Adapter with address 10.10.10.1 / 255.255.0.0
IP Forwarding enabled via Registry Edit (Windows XP / 7)
The IP packet that the Agent has received is addressed to 10.10.10.1:7070 (Virtual NIC).
What I can get to work:
Using WinPcap and WinPcap::SendPacket, I can attach to the Physical NIC and send the packet to that NIC. The packet is then forwarded to the Virtual NIC (I assume) and received by the Listener.
Problem: My target system does not have a Physical NIC
I tried installing a 2nd Microsoft Loopback Adapter, mimicking the addresses of the Physical NIC, attaching WinPcap to the 2nd Loopback Adapter, and sending the packet to it, just like I did with the Physical NIC, and... nothing. I've also tried experimenting with sending it to a Raw Socket, with no results (not sure if I'm doing something wrong, have never used raw sockets before).
So, I'm hoping someone can point me in the right direction. End goal is to get the pre-formed packet from the Agent to the Listener, and I really don't care what the mechanism is (WinPcap, Raw Sockets, something simple I'm too ignorant to know about, anything else), so long as the Listener receives the packet and the IP/UDP headers and Data payload are unmolested.
Cheers,
Chris
|
|
|
|
|
Hi!
How can I pass a string array to an LPARAM parameter in C++?
I've tried a
std::list<std::basic_string<TCHAR> type but my program crashes when I cast the values:
string_list szFile = (string_list) ppsp->lParam;
Thanks in advance.
|
|
|
|
|
What is string_list , and what does ppsp point to? There is so much detail missing from your question it's impossible to guess what the problem is.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
string_list is defined as:
typedef std::list<std::basic_string<TCHAR> > string_list;
ppsp is defined as
PROPSHEETPAGE* ppsp
|
|
|
|
|
Yes but what does the variable ppsp actually point to at the time of the crash? It is impossible, as I said earlier, to guess what is happening in your program without more detail as to the content of the variables being referenced and the actual instruction at the time of the crash.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
I usually create a dummy class/struct to hold the data to pass to LPARAM.
The dummy class is allocated on the heap and destroyed (delete) by the handler of the message. it contains a copy of the data.
not very practical for large data sets, but for small dataset it seems to be working fine.
(YMMV).
Watched code never compiles.
|
|
|
|
|
Supposing you can do that (e.g. you are not using it for posting a message to another application), you should pass the pointer to the list, e.g.
std::list< std::basic_string< TCHAR > > myList;
PostMessage(hWnd, wParam, (LPARAM) &myList);
std::list< std::basic_string< TCHAR > > * pList = (std::list< std::basic_string< TCHAR> > *) ppsp->lParam;
Veni, vidi, vici.
|
|
|
|
|
It might not be obvious for the OP that myList is either declared somewhere in a persistent location (and not on the stack) when using PostMessage() , or it can be on the stack as a temporary object but in that case SendMessage() must be used instead of PostMessage() and the message handler code must copy the contents of the list object because it might run out of scope after the message processor function returns. A perfect solution though and it shows that anything can be passed to the gui thread as a parameter.
The difference between SendMessage() and PostMessage() is that both functions put a message on the queue of the window to process but SendMessage() blocks the calling thread until the message is processed on the gui thread. If you use PostMessage() then the message is placed on the queue and your PostMessage() call returns immediately and this means that the stack object probably runs out of scope and the pointer parameter associated with the message will be invalid at the time the other thread processes the message.
|
|
|
|
|
Good point.
Veni, vidi, vici.
|
|
|
|
|
This code doesn't work.
I'm writting a Shell Extension (Property Page).
myList must point to a string array that represents the selected files.
In the AddPage function:
HRESULT CCSheetExt::AddPages (LPFNADDPROPSHEETPAGE lpfnAddPageProc, LPARAM lParam )
I have:
psp.lParam = (LPARAM) &myList;
All is OK. But in the
BOOL OnInitDialog ( HWND hwnd, LPARAM lParam ) function, I have:
string_list* pszFile = (string_list*) ppsp->lParam;
This line causes a program crash.
|
|
|
|
|
I think you should provide more code.
For instance, are you sure ppsp is a valid pointer?
Veni, vidi, vici.
|
|
|
|
|
std::list<std::basic_string<TCHAR> > m_lsFiles;
HRESULT CCSheetExt::Initialize (LPCITEMIDLIST pidlFolder, LPDATAOBJECT pDataObj, HKEY hProgID )
{
TCHAR szFile [MAX_PATH];
UINT uNumFiles;
HDROP hdrop;
FORMATETC etc = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
STGMEDIUM stg;
if ( FAILED( pDataObj->GetData ( &etc, &stg )))
return E_INVALIDARG;
hdrop = (HDROP) GlobalLock ( stg.hGlobal );
if ( NULL == hdrop )
{
ReleaseStgMedium ( &stg );
return E_INVALIDARG;
}
uNumFiles = DragQueryFile ( hdrop, 0xFFFFFFFF, NULL, 0 );
for ( UINT uFile = 0; uFile < uNumFiles; uFile++ )
{
if ( 0 == DragQueryFile ( hdrop, uFile, szFile, MAX_PATH ))
continue;
m_lsFiles.push_back ( szFile );
}
GlobalUnlock ( stg.hGlobal );
ReleaseStgMedium ( &stg );
return ( m_lsFiles.size() > 0 ) ? S_OK : E_FAIL;
}
HRESULT CCSheetExt::AddPages (LPFNADDPROPSHEETPAGE lpfnAddPageProc, LPARAM lParam )
{
PROPSHEETPAGE psp;
HPROPSHEETPAGE hPage;
TCHAR szPageTitle [MAX_PATH];
string_list::const_iterator it, itEnd;
LoadString (hModuleInstance,IDS_PROJNAME,szPageTitle,sizeof(szPageTitle));
szPageTitle[24] = '\0';
psp.dwSize = sizeof(PROPSHEETPAGE);
psp.dwFlags = PSP_USEREFPARENT | PSP_USETITLE | PSP_DEFAULT |
PSP_USECALLBACK;
psp.hInstance = hModuleInstance;
psp.pszTemplate = MAKEINTRESOURCE(IDD_PROPPAGE);
psp.pszIcon = 0;
psp.pszTitle = szPageTitle;
psp.pfnDlgProc = PropPageDlgProc;
psp.lParam = (LPARAM) &m_lsFiles;
psp.pfnCallback = PropPageCallbackProc;
psp.pcRefParent = (UINT*) &_Module.m_nLockCnt;
hPage = CreatePropertySheetPage ( &psp );
if ( NULL != hPage )
{
if ( !lpfnAddPageProc ( hPage, lParam ))
{
DestroyPropertySheetPage ( hPage );
}
}
return S_OK;
}
BOOL OnInitDialog ( HWND hwnd, LPARAM lParam )
{
PROPSHEETPAGE* ppsp = (PROPSHEETPAGE*) lParam;
string_list* pszFile = (string_list*) ppsp->lParam;
HANDLE hFind;
WIN32_FIND_DATA rFind;
string_list::const_iterator it;
it = pszFile->begin();
CCOMString File=it->c_str();
MessageBox (0, File, "Tests", 0);
}
|
|
|
|
|
How do you create the dialog (have I missed something?)?
Veni, vidi, vici.
|
|
|
|
|
This code come from a Shell Extension, so the dialog is created by Windows Explorer when the user right click on a file.
|
|
|
|
|
What you did is pretend that a string is a LPARAM. That does not change the contents of the variable though! If it had a size of 20 bytes before, it's size is still 20 bytes afterward.
An analogy would be to write 'glass' on a bucket, and then pour it's contents into a glass. Of course that glass will overflow. The water inside that bucket didn't magically compress.
The only case where this would work is when you initially started with an empty bucket, then poured a glass of water in it. At that point you know that while you see a bucket, it's contents is only one glass of water, so you can write 'glass' on it and pour that water back into another glass.
The same is true for typecasting: if you had previously (ab)used that string of yours to store an LPARAM, then - and only then - it would be valid to cast that string back to LPARAM and copy it over into a variable of that type.
As a rule of thumb, never use type-casting. If you think you need a type-cast, then either the type of one (or more) of the involved variables had been wrong from the start, or you're about to break the code. The former would be like using a bucket when you never need to store more than a glass full of water, the latter would be like pouring a bucket full of water into a glass.
There are very few exceptions to that rule, e. g. when you deal with a third-party library that uses inproper argument types such as LPARAM. The clean solution would be to fix that interface and use proper argument types, but sadly you don't have that option. MS should have fixed that 10 years ago, but they didn't.
This leaves you with the onus of assuring that the variables that you wish to pass actually fits into an LPARAM. As already pointed out, it does not. So you have to find another way, and that is passing a pointer to your string, rather than the string itself.
|
|
|
|
|
Hi,
I have a dialog box. from that dialog box, I am invoking a Modal dialog box. I have a slider control on that modal dialog box. Now I want when the user drags the slider control, value should get passed to the parent dialog box while scrolling. For example, while zooming an image, user drags the slider, Image size will increase appropriately.
Anybody have an idea.?
Regards,
Mbatra
|
|
|
|
|
the simplest way is to have the child call a member function on the parent.
void CChildDlg::OnHScroll(whatever)
{
CParentDlg *pParent = (CParentDlg *)GetParent();
pParent->UpdateZoomInfo(some info about the zoom);
}
|
|
|
|
|
You question is already answered, I just wanted to say that your solution seems to be a bad gui design. Setting the parameters of a disabled window from a modal dialog box isnt the way to go. I think you should do that from a modeless toolbox window.
|
|
|
|
|
hi guys,
i am using vs.net 2010 c++ and i need help:
i have
class school
{
public:
vector<student*>* students;
school()
{
vector<student*> s;
students = &s;
}
}
however when i try to
school s;
students.push_back(&s);
there is always an error,
Unhandled exception at 0x0f5757aa (msvcr100d.dll) in ast1.exe: 0xC0000005: Access violation reading location 0xccccccc0.
could anyone help me please.
|
|
|
|
|
There are so many issues with your code ...
Your vector is a pointer; you must allocate it before using it :
The student vector is a member of the class; so you must access it via the school class.
Change to (it is still very early here, and I've noy yet had coffee):
class school
{
public:
vector<student*> students;
school()
{
}
}
int main()
{
student* pStudent = new student; school aSchool; aSchool.students.push_back( pStudent );
return 0;
}
As a side note, your vector could contain "plain" students if the size and the data inside each student is small and simple enough; that would reduce the need for allocatation and de-allocation.
Also, have a look at smart/shared pointers for cleaner code (more advanced concepts).
Good luck.
Watched code never compiles.
|
|
|
|
|