|
thanks for the reply,
now it compiles. but the following code returns me the resource handle of the exe and not the dll:
AFX_MANAGE_STATE(AfxGetAppModuleState());
HINSTANCE hInstance = AfxGetResourceHandle();
PlaySound(MAKEINTRESOURCE(IDR_BTN_OVER),
hInstance,
SND_RESOURCE);
hInstance is 400000 which is the exe (should be 100000 for the dll)
can u help again?
thanks
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
Ummm... I'm shooting in the dark here. Try replacing your hInstance stuff with
HINSTANCE hInstance = AfxGetAppModuleState()->m_hCurrentInstanceHandle;
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
still not working.....
any other suggestions??
thanks again
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
Here I go again OK, I have not tried this, but I'm more or less confident it'll work. In your generated xxx.cpp where the DllMain function is defined, there is a static AFX_EXTENSION_MODULE object. Remove the static bit and declare it as extern in some header file, so that you can use it elsewhere. The hResource member of this AFX_EXTENSION_MODULE is what you need to pass to AfxSetResourceHandle . Remove the AFX_MANAGE_STATE stuff, it's not needed. Don't forget to restore the original resource handle upon exiting. Shake well and serve chilled. Good luck.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
thanks for the help...
i did that, and got compilation error regarding the extern AFX_EXTENSION_MODULE already defined????
can u help?
thanks again
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
Can you show the relevant code regarding the AFX_EXTENSION_MODULE both in the header and the .cpp file? Thanx
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
code taken from stdafx.h:
extern AFX_EXTENSION_MODULE GUILibDLL = { NULL, NULL };
code that uses in the cpp:
void CMyBtn::OnLButtonDown(UINT nFlags, CPoint point)
{
CButton::OnLButtonDown(nFlags, point);
AfxSetResourceHandle(GUILibDLL.hResource);
HINSTANCE hInstance = AfxGetResourceHandle();
PlaySound(MAKEINTRESOURCE(IDR_BTN_OVER),
hInstance,
SND_RESOURCE);
}
error in compilation:
Generating Code...
Linking...
GUILib.obj : error LNK2005: "struct AFX_EXTENSION_MODULE GUILibDLL" (?GUILibDLL@@3UAFX_EXTENSION_MODULE@@A) already defined in GUIBaseBtn.obj
StdAfx.obj : error LNK2005: "struct AFX_EXTENSION_MODULE GUILibDLL" (?GUILibDLL@@3UAFX_EXTENSION_MODULE@@A) already defined in GUIBaseBtn.obj
GUILib.obj : warning LNK4006: "struct AFX_EXTENSION_MODULE GUILibDLL" (?GUILibDLL@@3UAFX_EXTENSION_MODULE@@A) already defined in GUIBaseBtn.obj; second definition ignored
StdAfx.obj : warning LNK4006: "struct AFX_EXTENSION_MODULE GUILibDLL" (?GUILibDLL@@3UAFX_EXTENSION_MODULE@@A) already defined in GUIBaseBtn.obj; second definition ignored
Creating library Debug/GUILib.lib and object Debug/GUILib.exp
Debug/GUILib.dll : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
can u help me???
thanks for all the effort man
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
In the header:
extern AFX_EXTENSION_MODULE GUILibDLL; In the .cpp where your DLLMain is:
AFX_EXTENSION_MODULE GUILibDLL = { NULL, NULL }; Please tell me if this works. If so, I'd feel a little guilty that you might have applied tihs blindly without clearly understanding what's going on. Please consult some C++ tutorial or book on the meaning and use of extern and static .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
thanks.
now the dll compiles ok, but the client that uses the dll show me error on the method (that i showed you before):
void CMyBtn::OnLButtonDown(UINT nFlags, CPoint point) <br />
{<br />
CButton::OnLButtonDown(nFlags, point);<br />
<br />
======> AfxSetResourceHandle(GUILibDLL.hResource);<br />
<br />
HINSTANCE hInstance = AfxGetResourceHandle();<br />
PlaySound(MAKEINTRESOURCE(IDR_BTN_OVER),<br />
hInstance,<br />
SND_RESOURCE);<br />
<br />
AfxSetResourceHandle(AfxGetResourceHandle());<br />
}
it says:
"error C2065: 'GUILibDLL' : undeclared identifier"
where else should i define it in the dll beside dllmain file????
thanks again
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
I don't get it. How could the client fail in a function compiled inside the DLL?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Joaquín???
did u see my reply??
thanks
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
With regards to:
---> bReadible = !(nStatus == 0);
What does this mean? I have never seen code written like this before.
BOOL CRawPingDlg::IsSocketReadible(SOCKET socket, DWORD dwTimeout, BOOL& bReadible)
{
timeval timeout;
timeout.tv_sec = dwTimeout / 1000;
timeout.tv_usec = (dwTimeout % 1000) * 1000;
fd_set fds;
FD_ZERO(&fds);
FD_SET(socket, &fds);
int nStatus = select(0, &fds, NULL, NULL, &timeout);
if (nStatus == SOCKET_ERROR)
return FALSE;
else
{
bReadible = !(nStatus == 0);
return TRUE;
}
}
Thank you
|
|
|
|
|
The ! means NOT.
If you have a boolean value like true the operator ! will make it to false.
if nStatus has the value zero, the term wil be true. !(nStatus == 0) will make it false. It is the same if you write nStatus != 0.
sledge
|
|
|
|
|
esepich wrote:
bReadible = !(nStatus == 0);
What does this mean? I have never seen code written like this before.
The ! negates the statement. if (nStatus == 0) is TRUE, then the ! negates it and bReadible will be FALSE.
Douglas A. Wright
dawrigh3@kent.edu
|
|
|
|
|
Hiya I am trying to use a C# dll from my MFC program. But am having a big problem.
To use the C# dll, I have changed the compiler settings in my MFC program to - Use Managed Extensions and have included #using <mscorlib.dll>.
But as soon as I change to use managed extensions, my program will not run.
I am using .Net Framework Ver 1.1
Am I doing something wrong or is there another way??
Thanks.
|
|
|
|
|
As most of you know, I have been trying to do WYSIWYG printing from a CRichEditCtrl. The problems I was having was that the font bring printed was either too big or too small for the perscribed area.
OK, here is some what of a solution (except it isn't bullet proof!)
I create a device context to the display (while printing and in print preview), create the font scaled to the display and scaled to the printer. I then get the size of the line for each. I then calculate the scaling factor by getting the pixels in the X axis for both and dividing. For the printer here at work, it is 1200DPI, and the screen is 96DPI. This factor works out to be 12.5.
I then take the text width on the screen and multiply it by this ratio to
get an ideal output width. Divide the printer width by the ideal width that gives a ratio. I then get the average character width (from
GetTextMetrics - Printer). I then multiply this value with the ration from the ideal vs. actual printer. Then set this value in the LOGFONT.lfWidth and create a new font and select it into the printer device context.
As an example:
The width of text on the display is 410 pixels, this same string on the
printer (with no change in the character width) is 5352. The scaling factor of 12.5 means that the ideal lenght is 5112.5 pixels. The division of the Printer/Ideal = 1.066146. The average character width for the printer (with selected font) is 80 pixels. So, divide the 80 / 1.066... and the new character width is 75.
I read in Petzold's book that the lfWidth of the LOGFONT can be set to the tmAvgCharWidth from the TEXTMETRIC structure. AND, that it can be scaled.
The resulting output for the TIMES NEW ROMAN 12/10pt and COURIER NEW 12/10pt are right on (with the exception of a rounding error of a pixel). I do this for each line.
Now the caveat! When I use Arial Normal, the last line which isn't as long as the rest, and this creates an average character width is bigger than the previous lines.
I think there is something in the TrueType specification that can help with this. Does anyone know? If so, what?
Larry J. Siddens
Cornerstone Communications
TAME THE DOCUMENT MONSTER
www.unifier.biz
|
|
|
|
|
Hi All,
I want to create an imagelist from the files selected by the user. How can I do that? Is any sample code available?
With regards
A.Santosh
|
|
|
|
|
Hi there
I have a problem Maybe anyone is able to help me to solve this problem Here we go....
There is a window with a frequently changing background . Now i want to add a child window to this window. I also want that the child is "transparent". This isnt a great problem! Using GetDC, CreateCompatibleDC and BitBlt ... manually it works! But ... when the image of the parent window changes ... how can the "child" window notified so the WM_PAINT handler is fired??
Any ideas?
Thanks for reading
|
|
|
|
|
Hi,
WM_PAINT is called over 4 reasons:
1) application starts
2) application is being minimized
3) application is being maximized
4) a control is hiding an other control (moving over it)
if you want to "fire" WM_PAINT you can call either Invalidate or Redraw.......
hope this helps ya
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
an other approach :
in the dialog resources, check the 'clip children' and 'clip siblings' check boxes.....
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
I missed to mention that the other window which the child should be added is another application. I dont have control over it
I dont want to subclass the parent window because if my application crashes the other application must be restarted
|
|
|
|
|
I have a freeware program that was writtn in C++ MFC that I would like to study it's structure. Unfortunatly, I don't have access to the source code for debugging. Is there a way to get the source code from the bin disassembly?
|
|
|
|
|
|
Hi,
I'm writing a program that incorporates a Rich Edit control text editor containing consisting of an arbitrary number of "documents". On the left of the screen is a tree view, and on the right of the screen is a rich edit control for text editing. The user uses the tree view to create new "documents". By clicking on a tree view item, the document that that represents should appear in the rich text control on the right. All of this has to be saved to a single file (possibly using structs), and exported to an RTF. Saving to RTF is sorted (thanks to help from users here), but my problem is this:
How can I save an entire "document" to a string? I have tried saving to a char*, but I haven't got it working.
Note that I am using _no_ MFC, and I am not a very experienced programmer - I am still on a steep learning curve, so please forgive any idiocy in my code.
This is what I tried:
<br />
char* szTextTest;<br />
long nTest;<br />
<br />
static DWORD CALLBACK <br />
MyStreamInStringCallback(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)<br />
{<br />
memcpy(pbBuff,szTextTest,nTest);<br />
<br />
*pcb = cb;<br />
<br />
return 0;<br />
}<br />
<br />
void LoadRTFFromString(HWND hWnd, int nIDDlgItem)<br />
{<br />
EDITSTREAM es;<br />
<br />
es.pfnCallback = MyStreamInStringCallback; <br />
<br />
SendDlgItemMessage(hWnd,nIDDlgItem,EM_STREAMIN,SF_RTF,(LPARAM)&es);<br />
}<br />
<br />
<br />
static DWORD CALLBACK <br />
MyStreamOutStringCallback(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)<br />
{<br />
nTest = cb;<br />
szTextTest = new char[cb];<br />
memcpy(szTextTest,pbBuff,cb);<br />
<br />
*pcb = cb;<br />
<br />
return 0;<br />
}<br />
<br />
void SaveRTFToString(HWND hWnd, int nIDDlgItem)<br />
{<br />
EDITSTREAM es;<br />
<br />
es.pfnCallback = MyStreamOutStringCallback; <br />
<br />
SendDlgItemMessage(hWnd,nIDDlgItem,EM_STREAMOUT,SF_RTF,(LPARAM)&es);<br />
}<br />
Even if I could get the above working, would I be able to save the character pointer, szTextText, to file using WriteFile() and have it save all the text it has been allocated? I have only ever saved structures containing chars that aren't pointers to file so far...
If I can copy the whole of a formatted RTF file to a string, this is what I am thinking of doing to save the structure:
For each folder, copy text into the string such as "{{folder:name_of_folder;}}" or some such, and then add to the end of that the rich text that is associated with that folder. When reloading from file, I just need to search the string for occurrences such as "{{folder::...}}" etc in order to rebuild my treeview and associate text appropriately.
Thus the string created to hold the rich text needs to be infinitely long - or rather, it needs to be capable of holding formatted text that could run into the 100,000s of *words*.
To clarify, in case that was a bit long winded: I need to find a non-MFC way of saving and loading all of the text from a rich edit box into a string. And I need to be able to append to that string the text from _other_ rich edit boxes.
If anybody could give me any hints on how I could go about this, I'd be really grateful, as always.
Many thanks,
KB
|
|
|
|
|
|