|
Well, thanks, but that's not quite what I asked.
I was wondering if it was required to embed your methods in a struct for the example identified. If by your response you meant "yes, they must be embedded" then an explicit answer would be appreciated.
Thanks again.
Ed.
|
|
|
|
|
Edward G Dana wrote: Well, thanks, but that's not quite what I asked. Sorry, I misunderstood. But I think your question should really be directed at the author of the article.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
C++ doesn't natively support delegates and delegate implementation in C++ is quite messy especially if you try to support methods with variable number of parameters and parameter types - it also involves super-ugly method pointer casting. Delegates are simply ugly in C++, I recommend never using them if it isn't necessary. (For me using delegates is necessary only if a used 3rd party library makes it necessary to use delgates in its public interface...) I always prefer using old-school listener interfaces with old-school virtual methods (classes with pure or empty-bodied virtual methods only) to listen for events. Always consider alternatives and prefer readability of the resulting code. It doesn't worth trying to shape C++ into C#!
|
|
|
|
|
This is just me experimenting and playing. Seeing what I can do and make C++ do, for fun.
|
|
|
|
|
I have an executable compiled with x64 configuration.
I need to test it on Windows 7 64 bits.
when I run it, it crash when I return FALSE in InitInstance function.
BOOL CMyApp::InitInstance()
{
if (IsAppAlreadyStarted())
return FALSE;
InitCommonControls();
CWinApp::InitInstance();
if (!AfxOleInit())
{
AfxMessageBox(IDP_OLE_INIT_FAILED);
return FALSE;
}
AfxEnableControlContainer();
if(!CheckModule())
{
return FALSE;
}
}
when it is compiled with x32bits configuration and run on Windows 7 x64 there is no probleme.
Just when it is compiled with x64.
any help please?
|
|
|
|
|
I'd venture to say that something in CheckModule() is causing the crash and not returning FALSE. Although by returning FALSE you are indicating a failure on initialization anyway, so I'm not sure how gracefully it's supposed to go down after that.
|
|
|
|
|
Hi,
I'm using a .net dll in a Win32 application.
I want to print the DLL file location programetically.
I tried like as below , but it still displaying the EXE's (generated by my win32 app.) path -
-----------------------------------------------------------
HMODULE hmod = GetModuleHandle(TEXT("MyApp.dll"));
TCHAR szPath[MAX_PATH + 1] = {0};
DWORD dwLen = GetModuleFileName(hmod, szPath, MAX_PATH);
wprintf(L"CURRENT DIRECTORY: %s\n" ,szPath);
-----------------------------------------------------------
Please advice any new solution or any correction required (above code stuff) for the same.
|
|
|
|
|
The chances are that hmod is NULL because MyApp.dll has not been loaded into memory as required by the GetModuleHandle()[^] function. Always check return values from API calls, do not just assume that it works.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Hi Richard,
You mean to initialize 'hmod' to NULL as below -
HMODULE hmod =NULL;
hmod= GetModuleHandle(TEXT("MyApp.dll"));
if(hmod!=NULL)
{
DWORD dwLen = GetModuleFileName(hmod, szPath, MAX_PATH);
wprintf(L"CURRENT DIRECTORY: %s\n" ,szPath);
}
====================================
If the above code stuff as per your indication,then 'GetModuleHandle' not returning NULL .
And it printing the path of EXE not of required 'MyApp.dll'
Kindly guide me if i understood the wrong thing.
modified 7-Nov-12 6:38am.
|
|
|
|
|
No, I mean the value returned from GetModuleHandle() is NULL if that library has not been loaded into your address space. In which case you will get the path of your executable. Check the link to the documentation that I gave you.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Hi Richard,
I'm beginner to this area. I also gone through that document you sent me and got some idea.
But unable to conclude any way to get information on loaded DLL.
Actual requirement is to get both Dll's - "physical location" & "Version" information programeically from a Win32(vc++) application.
I tried 2-3 ways but still failing to fulfill my requirement.
Kindly share a detailed way or code then it will great to learn.
|
|
|
|
|
As I said before, you must load the DLL first, using the LoadLibrary() [^] function. Only then can you get the full path details. As to version information, you need the Version Information Functions[^].
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Thanks Richard,
Its working fine by using LoadLibrary().
Extracting the DLL's version info - i have check.
Mean while for my knowledge purpose ,can you please clarify one doubt.
Even though we are adding DLL reference through project-proporties, why it was still printing the application's Exe path (please refer the code stuff in my last reply) ??
Thanks
|
|
|
|
|
litu kumar wrote: why it was still printing the application's Exe path I have already explained twice. If the DLL has not been loaded into your application's address space then the call to GetModuleHandle() will return NULL ; something that you have not catered for in your code. If the module handle is NULL then GetModuleFileName() will return the path of your executable program. The sequence you should follow is:
HMODULE hmod = LoadLibrary(TEXT("MyApp.dll"));
if (hmod != NULL)
{
TCHAR szPath[MAX_PATH + 1];
DWORD dwLen = GetModuleFileName(hmod, szPath, MAX_PATH);
if (dwLen > 0)
{
wprintf(L"CURRENT DIRECTORY: %s\n" ,szPath);
}
else
{
}
}
else
{
}
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Thanks Richard for above information.
I have a small doubt, kindly clarify -
What is the difference between 'Adding the DLL reference from Project-properties' & 'LoadLibrary(MyApp.dll)' ??
-I mean in each case, how Dlls are being loaded (Dynamically\Statically)
"Adding the DLL reference from Project-properties " means - Right click on Project name -> Referenceses ..->Add New Reference... Then select 'MyApp.dll' from existing directory.
I can guess my answer but not sure. Thats why please ensure me.
Thanks
modified 8-Nov-12 9:07am.
|
|
|
|
|
I have never used dll's by adding to the project references; are you sure we are talking about C++ here? They are either linked in by adding the reference in the Linker properties of your project, or loaded dynamically by the LoadLibrary() function. Which version of Visual Studio are you using?
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
I'm trying to use another DLL from my Win32 dll.
So we can use external dll in either way.
why i asked that question , because if that external dll having different versions in same system.Then which version its taking while loading.
Actually one client requirement is there -
Our application should load this external DLL irrespective of certain DLL-location.
In above both ways[Adding reference AND LoadLibrary()] of DLL loading ,we are explicitly giving a DLL location Or placing the DLL in the same project location.
IS there any way we can make DLL to load independently(we'll not give explicit dll location or DLL itself).
Thanks
|
|
|
|
|
I'm not sure I fully understand what you are asking. However, you can include a library in your build process by adding the .LIB file to the linker input. This will add a reference to the associated DLL to the final program. At execution time the system will load the DLL when necessary, by searching for it in the standard library directories. If you wish to load it yourself using the LoadLibrary() function, then you can provide just the name, in which case the system will search for it as before, or you can provide the full path to an alternate version that you have installed elsewhere.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
hello everyone
we are hacker union Game source code group
We can help you get
someone or company file.photo.Record.Game source
code.
Have any questions about computer aspect need to
please contact us
plenty of Game source code. to sell or get to
designated game code
Yahoo Messenger:hacker240union
mail:hacker240union@yahoo.com.cn
|
|
|
|
|
Environment: Windows 7, Visual Studio 2008, C++ MFC
Question:
How does class AsyncSocket for the server side detect and notify the application when the client closes the connection?
Details:
I wrote the async article found here: Asynchronous TCP Part 1 as a learning tool. Now that I am using that knowledge in a working project I find that when the client closes the socket, I don’t see any results on the server side. I was expecting that OnClose() would be called, but that does not happen. On the client side, after closing, no data can be received until it is Initialized and connected again.
The problem is that in the real application, when the client closes and re-connects the interface protocol for the client requires that the server send some specific information. I am not seeing a way to detect that closure.
Edit: OnClose is declared public. That was an answer in another thread.
And again: I do not have the client code and have no control over the client side behavior.
and again: continued searching yielded something about the read() method getting a result or error. This server application never receives any data from the client and uses no reads. Do I still need to post a read to get a close status?
POSSIBLE ANSWER
My application uses C_Server, decended from CAsyncSocket, to post the Listen and call Accept(). In the call to Accept it creates an object from C_Server_Send to communicate with the client. When I add code to post a receive from C_Server_Send, and then close the client, OnClose() from C_Server_Send gets called. So, empirically, I conclude that Yes, I must post a receive to enable detection of client disconnect. Is that correct?
NEW PROBLEM:
How is C_Server_Send to be deleted.
First: C_Server_Send was newed from C_Server, but that object can create an indefiniate number of C_Server_Send objects as multiple clients connect. Must it keep track of each one.
Second: How does C_Server know that its time to delete an arbitrary instance of C_Server_Send?
Thanks for your time
modified 6-Nov-12 12:54pm.
|
|
|
|
|
Visual Studio, MFC, C++, Windows 7
I need to create some GUIs that I consider to be intermediate level, definatly more than the standard tutorial presents. Included is the ability to divide the screen into multiple areas and to dynamically draw some simple block diagrams with lines between the blocks with colors and labels.
Does someone have a link to some good articles or good books to suggest?
Thanks for your time
|
|
|
|
|
You probably need to look into Splitter Windows[^] and GDI+[^] for creating graphics. There are also some articles on GDI+ here[^].
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
char buffer[50]
int offset =3;
char Buffer[250];
sprintf_s(&buffer[offset],offset,"%s",Buffer);
When we use the above funcation and application crashed with the folloing message
---------------------------
Microsoft Visual C++ Debug Library
---------------------------
Debug Assertion Failed!
Program: xyz.exe
File: f:\dd\vctools\crt_bld\self_x86\crt\src\vsprintf.c Line: 244 Expression: ("Buffer too small", 0)
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.
(Press Retry to debug the application)
---------------------------
Abort Retry Ignore
---------------------------
OS used : Windows 7 32bit OS
Microsoft Visual Studio 2008 (VC++)
Version 9.0.30729.1SP
|
|
|
|
|
It looks like you are trying to store a 250 character string into a 50 character buffer, and you have told the formatter that the buffer is only 3 characters long. But ultimately your code makes little sense.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
A description I read had GetLastError where I expected WSAGetLastError and my searches did not return those pages. Thanks for the links.
Thanks for your time
|
|
|
|