|
dll_file.H
extern "C"
{
<code>__declspec</code>(<code>dllexport</code>) <code>bool</code> func1(<code>bool</code> a);
<code>__declspec</code>(<code>dllexport</code>) <code>bool</code> func2();
} dll_file.cpp
<code>__declspec</code>(<code>dllexport</code>) <code>bool</code> func1(<code>bool</code> a)
{
<code>int</code> x=0;
x=x+1;
return true;
}
<code>__declspec</code>(<code>dllexport</code>) <code>bool</code> func2()
{
<code>int</code> x=0;
x=x+1;
return <code>true</code>;
}
compiling - OK
LoadLibrary - OK
GetProcAddress(* both func1 & 2 *) - OK
calling func2 - OK
calling func1 - fails while returning back to the app
the error is:
The value of ESP was not properly saved across a function call.
Please
HH EE LL PP
Thank you for reading all this....
Hope u have the answer
|
|
|
|
|
ESP is the 32-bit stack pointer CPU register that points to locations in the stack segment. Where's the stack being used here? Look at your parameters.
So, we know ESP didn't get a value it expected. Why? I dunno for sure, but you are using C linkage and C doesn't support a bool type. I'm "guessing" the compiler doesn't care because it's being compiled as C++. This may work, I just haven't tried it yet. Also, fun1() is not referencing its param in the first place. Trying using it in the function and change it to an int -- just for testing.
Jeremy L. Falcon
"The One Who Said, 'The One Who Said...'"
<nobr>
Homepage : Feature Article : Sonork = 100.16311
|
|
|
|
|
The problem is in calling convention.
I guess that you use (CALLBACK *)(bool) or (__stdcall *)(bool) calling convention.
This is wrong in the case then you use "C" declaration of functions (extern "C" {}).
Coz in "C" declaration the caller should clean up stack but not callee.
So you should use (FAR *)(bool) or (__cdecl *)(bool) calling convention in case with "C" declaration.
P.S. Try to avoid using other types in function argument but integer. Coz they will be converted to integer anyway.
Have fun.
|
|
|
|
|
How do I close a view window problematically?
Do i have to close its frame window and it in some specific order?
Anon
|
|
|
|
|
Once you have a pointer to the view, just do:
pView->SendMessage ( WM_CLOSE );
--Mike--
Actual sign at the laundromat I go to: "No tinting or dying"
Like the Google toolbar? Then check out UltraBar, with more features & customizable search engines!
My really out-of-date homepage
Big fan of Alyson Hannigan and Jamie Salé.
|
|
|
|
|
Hi, Mike!
I encountered the same problem recently. You method wont work in a MDI application. Nothing will happen after you send WM_CLOSE.
Try the following step to verify by yourself:
1. Create a MDI application called "Tst" using AppWiz;
2. Craete a CloseView menu item under View menu
add response codes to this menu item in the CTstView class.
void CTstView::OnViewCloseview()
{
// TODO: Add your command handler code here
SendMessage(WM_CLOSE);
}
3. compiled it & run. Open some views, then click on CloseView menu item. You will see, nothing happen.
Is there anybody have a solution for this?
Comments & suggestion are greatly appreciated!
Wayne King
17 April 2002
|
|
|
|
|
hello!
I have a question: is it possible to take a CDC and pass it's display to a CBitmap class? For example, I would like to draw things in a window (using Rectangle, Ellipse and such) and then get the pixels in that window to CBitmap.
Once again, my apologies if this is a dumb question, I don't know much about this matters
marcela bovio
|
|
|
|
|
You can create a CBitmap and then select it into the DC. you could then use the CBitmap for whatever you wanted (as far as I'm aware).
CDC m_memDC;
CBitmap m_bmp;
CClientDC DC(this);
m_memDC.CreateCompatibleDC(&DC);
m_bmp.CreateCompatibleBitmap(&DC, m_ScreenSizeX, m_ScreenSizeY );
m_memDC.SelectObject( &m_bmp );
then draw into the m_memDC, and the m_bmp will be drawn to. I think you may need to unselect the CBitmap afterwards, so windows can free the GDI resources, but I'm not too sure.
Hope that helps,
Pete
|
|
|
|
|
Following code gives assertion fail under VS 7 (sometime with 6)
void StringFromWide(const wchar_t* pwch, int cch, char *psz, int szLen)
{
if(cch == 0) {
cch = wcslen(pwch);
// TODO it will display only first four char
}
if(cch > szLen) cch = szLen;
WideCharToMultiByte(CP_ACP, 0, pwch, cch, psz, cch, NULL, NULL);
psz[cch] = '\0';
}
As workaround I'm using following code
void StringFromWide(const wchar_t* pwch, int cch, char *psz, int szLen)
{
size_t szt;
if(cch == 0) {
szt = wcslen(pwch);
cch = sizeof(szt) ;// but this will retrieve four chars only
}
if(cch > szLen) cch = szLen;
WideCharToMultiByte(CP_ACP, 0, pwch, cch, psz, cch, NULL, NULL);
psz[cch] = '\0';
}
What is missing here?
|
|
|
|
|
I assume that valid null terminated strings are passed to the functions and that cch is the length (not including the ending NULL) of the original string (0 means compute) and szLen is the buffer size of the output including the room for the NULL terminator.
In such case, then if cch is greater or equal to szLen, psz[cch] will write one character after the end of the buffer (it should be psz[cch-1]).
Also the alternate code is wrong. The reason why it will often works is because szLen is greater that 4 in your case. Doing a sizeof on the returned size return the size of a variable of type size_t (which is probably an unsigned int or an unsigned long) and not the value hold in the variable.
Note that you uses assertion in your code to validate what you are doing. For ex. adding ASSERT(strlen(psz) < szLen) would have typically catch the error after the memory is overwritten but before the application crash so it would then be easy to apply the fix!
You should also check the result of the call to WideCharToMultiByte. If it fails (and it can), the output will contains garbage (if it wasn't initialized externally).
Also if output is really multibyte, then some UNICODE characters may be converted to 2 multibyte characters and it that case, the code would be incorrect.
Finally, it may be easier (and less error-prone) to uses macros like W2A (or classes like _bstr_t, CString, CComBSTR,...) to make conversions if you do not needs the extra functionality accessible only from the API.
In a few words: length and size are different... Knows what you are doing. Also, you may allocate a bit more memory than necessary to be on the safe side.
Philippe Mori
|
|
|
|
|
I salute you all,
I am new on MFC and right now i am trying to make a Microsoft's paint again.
My question is; Toolbox used in that program is CReBar object or CToolBar object? If CToolBar object how can i make two column toolbar.
Thank you.
I salute you all,
I am new on MFC and right now i am trying to make a Microsoft's paint again.
My question is; Toolbox used in that program is CReBar object or CToolBar object? If CToolBar object how can i make two column toolbar.
Thank you.
|
|
|
|
|
AFAIK, it uses a custom control within a control bar. You can find out for sure using Spy++ if you like. If you want to make a two column toolbar, i think you can just set the TBSTYLE_WRAPABLE style and set the width large enough for two buttons.
Developers that like shiny objects also dig case mods and scratch-and-sniff stickers. Klaus Probst, The Lounge
|
|
|
|
|
Is there a way to check if a file exist??
I'm using ::GetPrivateProfileXXX(...) funktion and if the file doesn't exist my app crashes... so I need a way to check if my INI exist!
------------------------------------
Rickard Andersson, Suza Computing
ICQ#: 50302279
I'm from the winter country SWEDEN!
------------------------------------
|
|
|
|
|
|
If you are using MFC you can use CFile like so..
if (f.Open(filename, CFile::modeRead) == TRUE) {
Otherwise you could do something similar with fopen() and check for NULL
-Jack
To an optimist the glass is half full.
To a pessimist the glass is half empty.
To a programmer the glass is twice as big as it needs to be.
|
|
|
|
|
#include <io.h>
...
if(_access(filename,0)==0){
}
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
FILE *fp = fopen("C:\\file.txt", "r");
if (!fp)
}
//... no file
{
else
{
//... there is a file
fclose(fp);
}
|
|
|
|
|
Also for information there is a simple way to check if a file is writable or not:
FILE *f = fopen(filename, "ab");
if (!f)
{
}
else
{
fclose(f);
}
|
|
|
|
|
My dialog is returning 20.. I can't figure out what this means.. anyone know?
The thread 0x1E0 has exited with code 20 (0x14)
Thanks,
Jim Beam
|
|
|
|
|
Who's returning 20? a dialog or a thread?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Joaquín M López Muñoz wrote:
Who's returning 20? a dialog or a thread?
That is my dialog's thread.. it was returning 2 (IDCANCEL) a while back.. now all of a sudden it is returning 20.
Thanks,
Jim Beam
|
|
|
|
|
Nevermind.. I see that the thread can exit with a different value than the dialog.
Sorry,
Jim Beam
|
|
|
|
|
I was wonderng, is there any way to use MFC Controls in a CDHtmlDialog?
Currently, I have a rather attractive looking GUI which is a modified off of a design I got from am "open source web design" website, which I have modded up with some javascript/etc for the purposes of my program.
However, I would like to have a list control in the lower portion of my screen.
a screenshot can be found --> http://24.150.11.236/gui1.png
what I would like, is to have a MFC Control in where I have ---List Control would go here---
(the design I modified to use http://www.oswd.org/viewdesign.phtml?id=559&referer=%2Fbrowse.phtml%3Fcategory%3Dclean%26offset%3D35%26sort%3Dposted_date%26min_rating%3D3 )
Currently, the only thing I can think of doing, is making a CDHTMLView type class, and using splitters and having the top be the HTML, with just a straight up MFC List control in the bottom half, but I'd much rather find a way to imbed it into the page itself.
any ideas?
|
|
|
|
|
create an ActiveX control that contains a list ctrl. embed that on your page.
-c
A man usually falls in love with a woman who asks the kinds of questions he is able to answer.
Ronald Colman
Smaller Animals Software, Inc.
|
|
|
|
|
I'll have to double-check this when i get home, but doesn't CDHtmlDialog use both an old-style dialog template and a HTML dialog template? What happens when you put the list control on the normal template?
Developers that like shiny objects also dig case mods and scratch-and-sniff stickers. Klaus Probst, The Lounge
|
|
|
|