|
LOL are we going to play message Tag =P
I am familiar with that section of the DLL in MSDN, which basically is talking about the types of DLL, but I will take another look at it.
FYI: I was able to convert the mfc app into a dll package and have it build cleanly and spit out the dll and lib files for linking. I have also been able to link the mfc dll from my console based app and have it load the dll into the process space.
What do I need to do to create an instance of my MFC app which is deriver from CWinApp and have it initialized to be able to show my Dialog based window? All the logic I have that I need is inside the dialog based window class..so do I even need to worry about CWinApp, is there a way just to create a modeless window that has it's own message loop?
Yours Truly, The One and Only!
|
|
|
|
|
I'll rip the relevent portions for you:
"A regular DLL, statically linked to MFC, has the following requirements:
This type of DLL must instantiate a class derived from CWinApp.
This type of DLL uses the DllMain provided by MFC. Place all DLL-specific initialization code in
the InitInstance member function and termination code in ExitInstance as in a normal MFC
application.
Even though the term USRDLL is obsolete, you must still define "_USRDLL" on the compiler command
line. This definition determines which declarations is pulled in from the MFC header files"
"Regular DLLs must have a CWinApp-derived class and a single object of that application class, as
does an MFC application. However, the CWinApp object of the DLL does not have a main message
pump, as does the CWinApp object of an application.
Note that the CWinApp::Run mechanism does not apply to a DLL, because the application owns the
main message pump. If the DLL opens modeless dialogs or has a main frame window of its own, the
application's main message pump must call a routine exported by the DLL that in turn calls the
CWinApp::PreTranslateMessage member function of the DLL's application object."
"A regular DLL, dynamically linked to MFC has the following requirements:
These DLLs are compiled with _AFXDLL defined, just like an executable that is dynamically linked
to the MFC DLL. But _USRDLL is also defined, just like a regular DLL that is statically linked to
MFC.
This type of DLL must instantiate a CWinApp-derived class.
This type of DLL uses the DllMain provided by MFC. Place all DLL-specific initialization code in
the InitInstance member function and termination code in ExitInstance as in a normal MFC
application.
Because this kind of DLL uses the dynamic-link library version of MFC, you must explicitly set
the current module state to the one for the DLL. To do this, use the AFX_MANAGE_STATE macro at
the beginning of every function exported from the DLL.
Regular DLLs must have a CWinApp-derived class and a single object of that application class, as
does an MFC application. However, the CWinApp object of the DLL does not have a main message
pump, as does the CWinApp object of an application.
Note that the CWinApp::Run mechanism does not apply to a DLL, because the application owns the
main message pump. If your DLL brings up modeless dialogs or has a main frame window of its own,
your application's main message pump must call a DLL-exported routine that calls
CWinApp::PreTranslateMessage.
Place all DLL-specific initialization in the CWinApp::InitInstance member function as in a normal
MFC application. The CWinApp::ExitInstance member function of your CWinApp derived class is
called from the MFC provided DllMain function before the DLL is unloaded."
Is that better?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
yes that is better ... LOL
Hopefully I can display the dialog window without too much work!
Yours Truly, The One and Only!
|
|
|
|
|
This was a lot simpler that I first thought
When I rediscovered AfxSetResourceHandle() everything came together!
Yours Truly, The One and Only!
|
|
|
|
|
How can I get CWnd object from dialog base and SDI project;
Thanks
|
|
|
|
|
Every CWnd-based object (dialogs, views, controls, etc) can be cast to a CWnd*.
Externally, you can do this:
CWnd* pWnd = (CWnd*)myDialog;
Internally you can do this:
CWnd* pWnd = this;
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Max++ wrote: How can I get CWnd object from dialog base and SDI project;
AfxGetMainWnd
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief
|
|
|
|
|
Sometime you can use of this .
|
|
|
|
|
Hi, I have a function called "search" which is a program that searches MySQL database for a match.
I get "error C2061: syntax error : identifier 'search' " when I try to compile the whole program.
My function declaration is the following:
int search(int, char*);
I call the function by:
search(argc, *argv[]);
I do not quite understand the int argc, char* argv[] that's pass to the function, but they were from the MySQL examples my function is based on. I still get the same error message when I take them out.
THANKS IN ADVANCE for the help.
The entire funtion looks like:
int search(int argc, char* argv[])
{
;
MYSQL *hnd=NULL; // mysql connection handle
const char *sinf=NULL; // mysql server information
hnd = mysql_init(NULL);
if (NULL ==
mysql_real_connect(hnd,SERVER_NAME,DB_USER,DB_USERPASS,DB_NAME,0,NULL,0))
{
fprintf(stderr,"Problem encountered connecting to the %s database on
%s.\n",DB_NAME,SERVER_NAME);
}
else
{
fprintf(stdout,"Connected to the %s database on %s as user
'%s'.\n",DB_NAME,SERVER_NAME,DB_USER);
sinf = mysql_get_server_info(hnd);
if (sinf != NULL)
{
fprintf(stdout,"Got server information: '%s'\n",sinf);
showTables(hnd);
showContents(hnd,TABLE_OF_INTEREST);
}
else
{
fprintf(stderr,"Failed to retrieve the server information string.\n");
}
mysql_close(hnd);
}
return 0;
}
void showTables(MYSQL *handle)
{
MYSQL_RES *result=NULL; // result of asking the database for a listing
of its tables
MYSQL_ROW row; // one row from the result set
result = mysql_list_tables(handle,NULL);
row = mysql_fetch_row(result);
fprintf(stdout,"Tables found:\n\n");
while (row)
{
fprintf(stdout,"\t%s\n",row[0]);
row = mysql_fetch_row(result);
}
mysql_free_result(result);
fprintf(stdout,"\nEnd of tables\n");
return;
}
void showContents
(
MYSQL *handle,
const char *tbl
)
{
MYSQL_RES *res=NULL; // result of querying for all rows in table
MYSQL_ROW row; // one row returned
char sql[1024], // sql statement used to get all rows
commastr[2]; // to put commas in the output
int i,numf=0; // number of fields returned from the query
sprintf(sql,"select * from %s",tbl);
fprintf(stdout,"Using sql statement: '%s' to extract all rows from the
specified table.\n",sql);
if (!mysql_query(handle,sql))
{
res = mysql_use_result(handle);
if (res)
{
numf = mysql_num_fields(res);
row = mysql_fetch_row(res);
fprintf(stdout,"Rows returned:\n\n");
while (row)
{
commastr[0]=commastr[1]=(char)NULL;
for (i=0;i
|
|
|
|
|
int search(int, char*); states that it will take an integer argument and a single string.
where as char *argv[] is a collection of strings (rather an array of strings).
You are getting error because you are passing array of strings to a function which expects a single string.
You can instead try the following:
<br />
int iCnt;<br />
for (iCnt=0; iCnt<argc; iCnt++)<br />
{<br />
search(iCnt, argv[iCnt]);<br />
}<br />
|
|
|
|
|
A dll file ,i only could see four export functions,these are DllCanUnloadNow,DllGetClassObject,DllRegisterServer and DllUnregisterServer using Dependency Walker. I think it is a COM component.
How could I find the other content so that I can use the dll(or COM component)?
Thanks
|
|
|
|
|
Those are the four exports you usually see on DLLs that are only used as COM servers. You can try #import ing the DLL, if it has a type library, the compiler can generate wrapper classes for you that may give a hint as to what's in the DLL.
|
|
|
|
|
In fact,there are somethings good,so i want to reuse it.
Of course,i should know what the content it export.
If I only use #import import the dll library,I remain don't know how to use the library,is it right?
|
|
|
|
|
you will need to register the DLL using regsvr32, use oleview to get an idea about what interfaces are available, this tool come with visual studio
you should know how to create and use a com object
Yours Truly, The One and Only!
|
|
|
|
|
kcynic wrote: How could I find the other content so that I can use the dll(or COM component)?
OleView Application will Help
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief
|
|
|
|
|
Thank you every one.
I will have a try,but if there is some other problems I hope I can gain some help here agin.
Thanks again
|
|
|
|
|
Hi all,
I've got the source code and compiled binary for a c++ class library, and I'd like to be able to instantiate & use the class in a c# application. What's the simplest way to do this? I've looked up resources, but they all appear to me more complicated than my basic level of understanding of MS C++ will allow to be helpful to me.
Can someone point me to a very simple recipe (and hopefully simple explanation too) on how to turn this unmanaged class into one which c# can use?
Also, will there be issues about "return data type matching" between c++ and c#?
Thanks,
cdj
|
|
|
|
|
You may want to post your question(s) on the C# board[^] as well!
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
We'll see how it goes here; if necessary, I will.
Thanks!
|
|
|
|
|
Well the person I know would have an answer replied here so...cool!
Good luck!
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
sherifffruitfly wrote: I've got the source code and compiled binary for a c++ class library, and I'd like to be able to instantiate & use the class in a c# application.
Then you need to compile it into a DLL, either COM or just standard. You can in both cases easily import your DLL into C# ( the plain dll via a p/invoke signature for each method you want to call ), but the COM way allows you to create class instances, p/invoke does not.
sherifffruitfly wrote: Also, will there be issues about "return data type matching" between c++ and c#?
If you use COM, then the IDE will fix that for you, if you use a dll, then you need to work it out for each method, for both return values, and values going in.
By far the most intelligent thing to do is to make your code managed, so you can create class instances and fully interact with them in C#.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I want instances, so I guess the COM compilation is what would be helpful. I'll look up how to do that.
The way I did it, I believe it's "just standard":
#ifndef DllExport
#define DllExport __declspec( dllexport )
#endif
...
class DllExport {...}
Thanks for the suggestions!
|
|
|
|
|
Hey, I want to write some status variable to the registry HKLM\Software. This works fine with admin privileges but not with user privileges (and VISTA UAC). Where can I store values for all users in registry or should I use files (e.g. counter for a trial period)?
Please help me...
-- modified at 12:45 Saturday 21st July, 2007
|
|
|
|
|
You can use the All Users\AppData dir - call SHGetFolderPath(CSIDL_COMMON_APPDATA) to get the path.
|
|
|
|
|
|