Returning values from mfc-dll to non-mfc dll

Hi,

I am new to mfc and dll.

I have a non-mfc dll that calls a mfc dll.  The mfc dll opens a dialog
box.  I have done this by

1. writing another func (LaunchDialog()) that does not return
mfc-resources or use mfc-rsources as parameteres in the mfc dll
2. CAll LaunchDialog() from the non-mfc dll by including all required
header and lib files.


extern "C" __declspec( dllexport ) int LaunchDialog()
   {
    AFX_MANAGE_STATE(AfxGetStaticModuleState());
    InputDialog indlg;

    return indlg.DoModal();
   }

The problem
--------------
I actually need to pass the value of the text input in the dialog box
back to the calling non-mfc dll.  I am sure there is a documented
method, can any one please tell me how to do it?  Sample code or
pointers to web sites?

Thank you very much.
0
putmanju (12)
11/9/2003 7:11:29 PM
vc.mfc 33608 articles. 0 followers. Follow

5 Replies
493 Views

Similar Articles

[PageSpeed] 41

>I actually need to pass the value of the text input in the dialog box
>back to the calling non-mfc dll.  I am sure there is a documented
>method, can any one please tell me how to do it?  Sample code or
>pointers to web sites?

Have a suitable parameter for your LaunchDialog function so that you
can pass the string back. I'd have an LPTSTR and integer length
parameter as often used in the Win32 APIs:

int LaunchDialog( LPTSTR pRetString, int MaxLen )
{
	// your code
	// copy the string back to the caller's supplied buffer
	lstrcpyn( pRetString, YourString, MaxLen );
}

and call it something like this:

	TCHAR szString[100];
	LaunchDialog( szString, 100 );

Dave
-- 
MVP VC++ FAQ: http://www.mvps.org/vcfaq
0
davidl (422)
11/9/2003 7:49:01 PM
Hi,

I have tried what you asked me to, I am printing the returned value to
check if its working.  Nothing is getting printed in the file.

extern "C" __declspec( dllexport ) int LaunchDialog(LPTSTR pRetString,
int MaxLen )
   {
    AFX_MANAGE_STATE(AfxGetStaticModuleState());
    InputDialog dlg;
	CString str =dlg.m_edit;  //from the dialog box
	
	lstrcpyn( pRetString, str, maxlen);


	return dlg.DoModal();
		
   }


Calling from non-mfc dll
int check()
{
	TCHAR c[100];
	FILE *fp;

	int i=LaunchDialog(c, 100);
	fp=fopen("c.txt", "w");
	fprintf(fp, "The string: %s", TCHAR(c));
	
	return(i);
}


I also tried something in msdn
char *ch = new TCHAR[str.GetLength()+1];
_tcscpy(ch, str);

that doesnt work either.  It prints some junk.

Is there something wrong with the printing or the conversion from
tchar printing to a file?  I am not too clear about UNICODE, ANSI etc.
 Do I need to make changes in some settings??

Thanks in advance.

mp





David Lowndes <davidl@mvps.org> wrote in message news:<296tqvovr49tf0mtn2covli3m46na5v7ng@4ax.com>...
> >I actually need to pass the value of the text input in the dialog box
> >back to the calling non-mfc dll.  I am sure there is a documented
> >method, can any one please tell me how to do it?  Sample code or
> >pointers to web sites?
> 
> Have a suitable parameter for your LaunchDialog function so that you
> can pass the string back. I'd have an LPTSTR and integer length
> parameter as often used in the Win32 APIs:
> 
> int LaunchDialog( LPTSTR pRetString, int MaxLen )
> {
> 	// your code
> 	// copy the string back to the caller's supplied buffer
> 	lstrcpyn( pRetString, YourString, MaxLen );
> }
> 
> and call it something like this:
> 
> 	TCHAR szString[100];
> 	LaunchDialog( szString, 100 );
> 
> Dave
0
putmanju (12)
11/9/2003 11:15:13 PM
Hi, 
I made a mistake in the order of the calls, what you said works
perfectly.  Thank you very very much.

Manju


David Lowndes <davidl@mvps.org> wrote in message news:<296tqvovr49tf0mtn2covli3m46na5v7ng@4ax.com>...
> >I actually need to pass the value of the text input in the dialog box
> >back to the calling non-mfc dll.  I am sure there is a documented
> >method, can any one please tell me how to do it?  Sample code or
> >pointers to web sites?
> 
> Have a suitable parameter for your LaunchDialog function so that you
> can pass the string back. I'd have an LPTSTR and integer length
> parameter as often used in the Win32 APIs:
> 
> int LaunchDialog( LPTSTR pRetString, int MaxLen )
> {
> 	// your code
> 	// copy the string back to the caller's supplied buffer
> 	lstrcpyn( pRetString, YourString, MaxLen );
> }
> 
> and call it something like this:
> 
> 	TCHAR szString[100];
> 	LaunchDialog( szString, 100 );
> 
> Dave
0
putmanju (12)
11/10/2003 12:04:12 AM
>I have tried what you asked me to, I am printing the returned value to
>check if its working.  Nothing is getting printed in the file.

Debug your code with the IDE's debugger and see what's really
happening - I think you'll find it very illuminating.

What you posted can't be your real code, because it wouldn't compile,
so it's difficult to know where your problem lies for sure.

>    InputDialog dlg;
>	CString str =dlg.m_edit;  //from the dialog box
>	
>	lstrcpyn( pRetString, str, maxlen);
>	return dlg.DoModal();

The above is surely in the wrong order? How can you copy the string
before you've called DoModal in order to enter it (I'm assuming you
enter the string from the dialog).

>	fprintf(fp, "The string: %s", TCHAR(c));

Dunno what TCHAR(c) is supposed to be doing there, you only need:

	fprintf(fp, "The string: %s", c );

Dave
-- 
MVP VC++ FAQ: http://www.mvps.org/vcfaq
0
davidl (422)
11/10/2003 12:13:15 AM
See below...
On 9 Nov 2003 15:15:13 -0800, putmanju@hotmail.com (mp) wrote:

>Hi,
>
>I have tried what you asked me to, I am printing the returned value to
>check if its working.  Nothing is getting printed in the file.
>
>extern "C" __declspec( dllexport ) int LaunchDialog(LPTSTR pRetString,
>int MaxLen )
>   {
>    AFX_MANAGE_STATE(AfxGetStaticModuleState());
>    InputDialog dlg;
>	CString str =dlg.m_edit;  //from the dialog box
****
So you are taking the uninitialized value from the dialog box (dlg.m_edit will necessarily
be empty, unless you did something really unusual) and store it, copy that value to your
output buffer, then invoke the dialog? It is not surprising this would produce a
meaningless result.
*****
>	
>	lstrcpyn( pRetString, str, maxlen);
>
>
>	return dlg.DoModal();
*****
	int result = dlg.DoModal();
	if(result == IDOK)
                 {
                  lstrcpyn(pRetString, dlg.m_edit, MaxLen);
                 }
            return result;

Note that there is little value to storing the CString value from dlg.m_edit to another
CString just so you can copy it using a short variable name as an argument.
*****
>		
>   }
>
>
>Calling from non-mfc dll
>int check()
>{
>	TCHAR c[100];
>	FILE *fp;
>
>	int i=LaunchDialog(c, 100);
>	fp=fopen("c.txt", "w");
>	fprintf(fp, "The string: %s", TCHAR(c));
>	
>	return(i);
>}
>
>
>I also tried something in msdn
>char *ch = new TCHAR[str.GetLength()+1];
>_tcscpy(ch, str);
>
>that doesnt work either.  It prints some junk.
>
>Is there something wrong with the printing or the conversion from
>tchar printing to a file?  I am not too clear about UNICODE, ANSI etc.
> Do I need to make changes in some settings??
>
>Thanks in advance.
>
>mp
>
>
>
>
>
>David Lowndes <davidl@mvps.org> wrote in message news:<296tqvovr49tf0mtn2covli3m46na5v7ng@4ax.com>...
>> >I actually need to pass the value of the text input in the dialog box
>> >back to the calling non-mfc dll.  I am sure there is a documented
>> >method, can any one please tell me how to do it?  Sample code or
>> >pointers to web sites?
>> 
>> Have a suitable parameter for your LaunchDialog function so that you
>> can pass the string back. I'd have an LPTSTR and integer length
>> parameter as often used in the Win32 APIs:
>> 
>> int LaunchDialog( LPTSTR pRetString, int MaxLen )
>> {
>> 	// your code
>> 	// copy the string back to the caller's supplied buffer
>> 	lstrcpyn( pRetString, YourString, MaxLen );
>> }
>> 
>> and call it something like this:
>> 
>> 	TCHAR szString[100];
>> 	LaunchDialog( szString, 100 );
>> 
>> Dave

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15975)
11/10/2003 2:41:43 AM
Reply:

Similar Artilces: