|
Cool! Glad you found it!
Abyss wrote: It does not matter if the DLL is MFC Extension or Regular DLL. In both cases it works fine.
It will probably matter eventually - the initialization in the extension DLL is important to many
of the MFC classes. It just depends which ones you use and where The CWinApp class is one of
them - it's initialization in the DLL module is used with window/dialog creation for example.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Hi I'm trying to call a function in a DLL and am having trouble doing so because it uses callback and I need the function in the DLL to write to my dialog.
The function prototype is like this:
<br />
UINT CALLBACK PatchApply(LPSTR lpszCmdLine,LPVOID (CALLBACK *lpfCallBack)(UINT Id, LPVOID lpParm),BOOL WaitFlag);
and the example given is in C and not C++ (i'm making a dialog based program in unmanaged VC++ 7
Example snippet :
<br />
typedef LPVOID (CALLBACK* PATCHCALLBACK)(UINT, LPVOID);<br />
<br />
UINT CALLBACK PatchApply( LPSTR CmdLine, <br />
PATCHCALLBACK CallBackFn, <br />
BOOL WaitFlag);<br />
<br />
LPVOID CALLBACK __export CallBack( UINT Id, LPVOID Parm );<br />
My callback function is declared as
LPVOID CALLBACK CallBack(UINT Id, LPVOID Parm);<br />
and in the callback program I try to write to a listbox on my dialog.
Prior to calling I do like this:
<br />
typedef LPVOID (CALLBACK* PATCHCALLBACK)(UINT, LPVOID);<br />
PATCHCALLBACK CallBackPtr; <br />
CallBackPtr = MakeProcInstance((FARPROC) CallBack, AfxGetInstanceHandle());<br />
<br />
nRetCode = PatchApply(lpszBuf, CallBackPtr, TRUE);<br />
The MakeProcInstance is also from example and I try to call the PatchApply function directly from the DLL as I link the lib file into my program.
I get this error "cannot convert from 'overloaded-function' to 'FARPROC'" with above code and don't know what to do
Can anyone tell med what I need to do to call this succesfully ?
Thanks
|
|
|
|
|
Well, one thing is that FARPROC is defined as
typedef INT_PTR (WINAPI *FARPROC)(void);<br />
whereas your callback function has a return type of LPVOID .
So it looks like you're trying to redefine the return type of the callback function when you cast it to (FARPROC) in the call to MakeProcInstance .
Also, FARPROC has no arguments, so it is a very different function signature.
-- modified at 13:32 Sunday 27th May, 2007
--------------------------------
"All that is necessary for the forces of evil to win in the world is for enough good men to do nothing" -- Edmund Burke
|
|
|
|
|
Hi all:
My program crashed at the line:
for (vector<int>::iterator it = list.begin(); it != list.end(); ++it) {
if (*it < 0) list.erase(it);
}
//Filtering out all the negative numbers from a vector.
I am sure that it is vector::erase(it) is causing all the pain, but not sure how to fix.
Can anyone help?
Thank you
|
|
|
|
|
When you call erase, it will invalidate your current iterator and all iterators that follow. Thus, when you erase something and try to increment this same iterator, this will cause an exception. The erase function returns an iterator to the next valid element, you need to use that.
Try to change your code to something like this:
while (it != list.end())<br />
{<br />
if (*it<0)<br />
{<br />
it = erase(it);<br />
}<br />
else<br />
it++;<br />
}
|
|
|
|
|
Thank you very much, it worked.
|
|
|
|
|
Cedric's given you an answer, and its good that it works - here's another way - include <algorithm> and use remove_if ..
the following link shows how :-
http://support.microsoft.com/kb/156532[^]
'g'
|
|
|
|
|
Hi 'g':
Thank you very much for bringing that into attentaion as well.
I have learnt a lot from both of you.
Thank you
|
|
|
|
|
dear friends,
i am encountering a strange problem.
i have built a DLL containing a MFC Dialog in which i have inserted an active X component - Date Time Picker control.
when i try to call this dialog from my main application
the dialog doesnot appear at all.
i tried with simple MFC Dialog based exe it works fine.
can any one of you guide me on this
thanks and regards
prashant
|
|
|
|
|
have you put AFX_MANAGE_STATE( AfxGetStaticModuleState()); in dll before creating the dialog?
nave
|
|
|
|
|
hi naveen,
yes i have added the above macro correctly.
can you please try it once, and tell me if it works
thanks and regards
prashant
|
|
|
|
|
can you show me how you called the dialog from the exe?
prash pissey wrote: can you please try it once, and tell me if it works
nave
|
|
|
|
|
hi naveen,
here is he code
extern "C" __dllspec(dllexport) void CallDate()
{
AFX_MANAGE_STATE( AfxGetStaticModuleState());
CDateTimeDlg DateTimeDlg;
DateTimeDlg.DoModal();
}
thanks and regards
prashant
|
|
|
|
|
did u try removing that activex from the dialog?
where did u get this datetimectrl ActiveX? Is it the normal Date Time control among the windows common controls?
nave
|
|
|
|
|
hi nave,
it is Microsoft Date Time Picker control.
open VC++ go to dialog editor ,
right click, you will get a menu,
select "insert Active X",
a list of Active x components will appear.
in the list select "Microsoft Date Time Picker Control".
i have tried to remove the active X component and calling the DLL dialog.
then the dialog appears,works fine.
i suspect that acive x is causing the problem
thanks and regards
prashant
thanks and
|
|
|
|
|
ok I got the pblm. Put AfxEnableControlContainer(); in the InitInstance() function of the dll and then try.
nave
|
|
|
|
|
hi naveen,
i tried by adding AfxEnableControlContainer(); in the InitInstance() function of the dll . it didn't work.
if you have code sample. pls give it to me.
prashant
|
|
|
|
|
send me your mail id...
nave
|
|
|
|
|
hi naveen,
here is my mail id
pissey123@indiatimes.com
thanks and regards
prashant
|
|
|
|
|
I"m building a screen reader for my college project and I need to detect
words by the cursors position. Active Accessibilty(aac) is doing the job
well, but it gives me a full sentence and not the specific word in the
sentence where the mouse coursor is pointing at. For the ability to get this
word I need the Font properties, mainly width and height, of this acc
object. I need something like GetTextExtent but for the AccObject.
So how can I get the Font properties of an ActiveAccessibilty Object?
|
|
|
|
|
Hi to everyone, i have this code that tansform an IlpImage* in a bmp format..
char* bitmap_buf;
IplImage* image;
BITMAPINFOHEADER InfoBitmapHdr;
BITMAPFILEHEADER BitmapHdr;
image=cvLoadImage("nome_file.ext",1);
memset(&InfoBitmapHdr, 0, sizeof(BITMAPINFOHEADER));
memset(&BitmapHdr, 0, sizeof(BITMAPFILEHEADER));
InfoBitmapHdr.biWidth = image->width;
InfoBitmapHdr.biHeight = image->height;
InfoBitmapHdr.biSize = sizeof(BITMAPINFOHEADER);
InfoBitmapHdr.biPlanes = 1;
InfoBitmapHdr.biBitCount = 24;
InfoBitmapHdr.biSizeImage = image->imageSize;
BitmapHdr.bfType = 0x4d42;
BitmapHdr.bfSize = (DWORD) image->imageSize + sizeof(BITMAPFILEHEADER);
BitmapHdr.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + InfoBitmapHdr.biClrUsed * sizeof (RGBQUAD);
bitmap_buf= new char[image->imageSize];
memcpy( bitmap_buf, (char*)&BitmapHdr, sizeof(BITMAPFILEHEADER));
memcpy( bitmap_buf + sizeof(BITMAPFILEHEADER), (char*)&InfoBitmapHdr, sizeof(BITMAPINFOHEADER));
memcpy( bitmap_buf + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER), (char*)image->imageData, image->imageSize - 60);
Can you tell me which variable must i use to visualize the bmp in a picture box of a window form application in visual c++??
Thanks for answers, regards.
|
|
|
|
|
You have all the info you need to use CreateDIBSection() to create a HBITMAP that can be set to
a picture box.
Even without a picture box, you could use StretchDIBits() with a BITMAPINFO and a pointer to
the image bits to draw the image diectly on a window.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Thanks Mark, i see form msdn the definition of hBitmap = CreateDIBitmap(hDC, lpInfo, CBM_INIT, lpBits, lpInfo,wUsage); but i can't associate my variable to that are required in the function. For example hdc(where is in my code??), lpinfo( InfoBitmapHdr.biWidth),CBM_INIT,lpbits(??),lpinfo(InfoBitmapHdr.biHeight),wUsage(??)
Thanks for answers, regards.
|
|
|
|
|
A BITMAPINFOHEADER is part of the BITMAPINFO struct required by CreateDIBSection().
The HDC is only used for bitmaps requiring a color table. The palette selected into the DC
is used by CreateDIBSection() to construct a color table when necessary. Since you have 24-bit
pixels it's not needed. You can use a screen DC.
I haven't used IplImage but based on what I've seen, the imageSize member is the size of just
the pixel data, not pixel data with Windows BITMAPINFO stuff attached. If I'm wrong you'll
have to adjust the following code a bit
Here's a modified version of your sample code. Note that this code is hardwired for 24-bit
images...
BYTE* bitmap_buf;
IplImage* image;
BITMAPINFO bmi;
image=cvLoadImage("nome_file.ext",1);
memset(&bmi, 0, sizeof(BITMAPINFO));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = image->width;
bmi.bmiHeader.biHeight = image->height;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 24;
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biSizeImage = image->imageSize;
HDC hdc = ::GetDC(0);
HBITMAP hBitmap = ::CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, &bitmap_buf, NULL, 0);
::ReleaseDC(0, hdc);
if (hBitmap)
{
memcpy( bitmap_buf, image->imageData, image->imageSize );
...
}
*EDIT*
I looked up the IplImage structure. I'm not sure what the default alignment of rows of pixel
data is in OpenCV, but for a Windows DIB, rows must be aligned to a DWORD (4-byte) boundary.
If this does not match the IplImage alignment (based on image->widthStep) then your resulting
bitmap will look skewed
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Thanks for answers,it's very useful.
There's a prolem when i try to compile:
HBITMAP hBitmap = ::CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, &bitmap_buf, NULL, 0);
generate error C2664: 'CreateDIBSection' : cannot convert parameter 4 from 'BYTE **' to 'void **'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
so i try to do a safe cast, i add this line before the CreateDIBSection
void* buff=safe_cast<void *="">(bitmap_buf);
and use &buff instead of bitmap_buf in CreateDIBSection but the result is a list of build error:
error LNK2028: unresolved token (0A0002FA) "extern "C" int __stdcall ReleaseDC(struct HWND__
*,struct HDC__ *)" (?ReleaseDC@@$$J18YGHPAUHWND__@@PAUHDC__@@@Z) referenced in function "private: void __clrcall WinCam::Form1::capimgbut_Click(class System::Object ^,class System::EventArgs ^)" (?capimgbut_Click@Form1@WinCam@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
WinCam.obj : error LNK2028: unresolved token (0A0002FB) "extern "C" struct HBITMAP__ * __stdcall CreateDIBSection(struct HDC__ *,struct tagBITMAPINFO const *,unsigned int,void * *,void *,unsigned long)" (?CreateDIBSection@@$$J224YGPAUHBITMAP__@@PAUHDC__@@PBUtagBITMAPINFO@@IPAPAXPAXK@Z) referenced in function "private: void __clrcall WinCam::Form1::capimgbut_Click(class System::Object ^,class System::EventArgs ^)" (?capimgbut_Click@Form1@WinCam@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
...and so on.
I don't know why...
Thanks however for help.
Regards.
|
|
|
|
|