473,396 Members | 1,770 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Creating modal dialog in vc++

Hi All,

I have developed a VC+ dll file which provides a product key for my msi setup file. This VC++ dll work fine together with my setup file. but,

my problem is, i have given a message box inside the dll for showing error message while an invalid key is entered. but the messagebox is not shown as modal dialog. i must want to show this as modal dialog.

in my VC++ method i have passed the MSIHANDLE from the msi file.

how can i change the message as modal dialog?

my code is:

#include "windows.h"
#include "msi.h"
#include "msiquery.h"

extern "C" _declspec(dllexport) UINT __stdcall VerifyPID(MSIHANDLE hInstall);

TCHAR* GetPIDValue(TCHAR*);

extern "C" UINT __stdcall VerifyPID(MSIHANDLE hInstall)
{
UINT nRetVal = 0;
UINT uiMsiRc;
TCHAR szPidKey[MAX_PATH];
TCHAR szSourceDir[MAX_PATH];
TCHAR* lpszPidValue;
DWORD dwBuffer;

dwBuffer = sizeof(szSourceDir)/sizeof(TCHAR);

uiMsiRc = MsiGetProperty(hInstall, TEXT("SourceDir"), szSourceDir, &dwBuffer);

if (ERROR_SUCCESS != uiMsiRc)
{
MessageBox(NULL, "Not able to retrieve the SourceDir property. The setup may be corrupt. Please contact Technical Support.", "Setup Error", MB_OK | MB_ICONEXCLAMATION);
return 0;
}

lpszPidValue = GetPIDValue(szSourceDir);

dwBuffer = sizeof(szPidKey)/sizeof(TCHAR);

uiMsiRc = MsiGetProperty(hInstall, TEXT("PIDKEY"), szPidKey, &dwBuffer);

if (ERROR_SUCCESS != uiMsiRc)
{
MessageBox(NULL, "Not able to retrieve PIDKEY property. The setup may be corrupt. Please contact Technical Support.", "Setup Error", MB_OK | MB_ICONEXCLAMATION);
return 0;
}

int str = lstrcmp(szPidKey, lpszPidValue);

if (str == 0)
MsiSetProperty(hInstall, "PIDCHECK", "TRUE");
else
{
MsiSetProperty(hInstall, "PIDCHECK", "FALSE");
MessageBox(NULL,"Please enter the correct product registration code!", "Invalid Key", MB_OK | MB_ICONINFORMATION);
}
return 0;
}

TCHAR* GetPIDValue(TCHAR* lpszSourceDir)
{
return "123-456-789";
}

Please help to resolve it.

Thanks in advance.

Regards,
Dhanasekaran. G
Apr 18 '08 #1
1 3081
weaknessforcats
9,208 Expert Mod 8TB
Your code works for me after I changed it this way:
Expand|Select|Wrap|Line Numbers
  1. void __stdcall DisplayFromDll()
  2. {
  3.     MessageBox(NULL, TEXT("Not able to retrieve the SourceDir property. The setup may be corrupt. Please contact Technical Support."), TEXT("Setup Error"), MB_OK | MB_ICONEXCLAMATION);
  4.  
  5. }
  6.  
Notice I used the TEXT macro. Otherwise, your code won't compile.

Next, be sure your DLL project has a DEF file that exports the C++ name as a name you can use with GetProcAddress:
Expand|Select|Wrap|Line Numbers
  1. ;BEGIN ADLL.DEF FILE
  2. ;This DEF file is required becuase the argument to GetProcAddress()
  3. ;for the function is a C-string and it will never be equal to the
  4. ;C++ mangled name for the function
  5. ;This DEF file maps the mangled name to a name that can be used with GetProcAddress()
  6. ;Note also: Change project settings in Visual Studio to send the LINK this def file.
  7. ;Visual Studio.NET: Project Properties/Linker/Input/Module Definition File/...Path to the def file\Adll.def
  8. LIBRARY ADll 
  9. EXPORTS 
  10. ;Exported Name    C++ Mangled Name
  11. DisplayFromDll =  ?DisplayFromDll@@YGXXZ
  12. ;END DEF FILE 
  13.  
Next, be certain to set the path to the DEF file in the linker input project property.

Finally, I called the funciton:
Expand|Select|Wrap|Line Numbers
  1. //First, load the dll into memory
  2.     HMODULE theDll = LoadLibrary(TEXT("C:\\Scratch\\Instructor\\Debug\\DLLExample.dll"));
  3.     if (!theDll)
  4.     {
  5.         MessageBox(NULL, TEXT("Dll Failed to Load"), TEXT("Fatal Error"), MB_OK | MB_ICONEXCLAMATION);
  6.         return 1;
  7.     }
  8.  
  9.     //Second, get the address of the desried function from the dll
  10.     FARPROC addr = GetProcAddress(theDll, "DisplayFromDll");
  11.     if (!addr)
  12.     {
  13.  
  14.         //Look up the error in the system errors list
  15.         unsigned int what = GetLastError();
  16.         if (what == ERROR_PROC_NOT_FOUND)
  17.         {
  18.             MessageBox(NULL, TEXT("Function not found in the dll"), TEXT("Fatal Error"), MB_OK | MB_ICONEXCLAMATION);
  19.  
  20.         }
  21.         return 2;
  22.     }
  23.     cout << "The function has been located in the dll" << endl;
  24.     //Declare a function pointer that can accept the address of the function.
  25.     //You will need to know the function prototype to do this.
  26.     //Dll function prototypes should be provided by the vendor of the dll
  27.     void (__stdcall *DisplayFromDll)();
  28.     //Type-cast the address returned from GetProcAddress to the function pointer type
  29.     DisplayFromDll = reinterpret_cast<void (__stdcall *)()>  (addr);
  30.     //Now use the function pointer to call the function:
  31.     DisplayFromDll();
  32.  
Apr 18 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Patrick Lim | last post by:
Here is the problem: I have written a non-modal frame class in Java for displaying help text when a user is using an application. It works as desired in that if the user selects "help" again,...
2
by: Gilles T. | last post by:
Hi, How I can refresh a modal dialog in asp.net? I open a modal dialog in first with a dropdownlist. To add a element in my dropdownlist (table), I open a second modal dialog to ask element and...
2
by: cassidyc | last post by:
Hi, I was wondering if anyone has come accross this issue? And if they have any solutions I have that can create new copies of itself Form1 as = new form1(); af.show(); This form can also...
6
by: Burt | last post by:
I need to put up a simple modal dialog, and am surprised how hard it seems to be. Am I missing something here? I have created a dialog resource IDD_DELETE_S9. It has some static text plus 3...
10
by: Guadala Harry | last post by:
I have a modal dialog that currently does all of the following except item 4. 1. lets users select a graphic from a list of thumbnails (and when selected, displays the full-size image in a...
2
by: sthrudel | last post by:
Hi! I'm working on a web application in Asp.net and what I would like to have is a cross borwser modal dialog which accepts user's input. I would like to catch what the user clicked on the...
0
by: dattaforit | last post by:
Hello Friends, I am using VC++ 2005. I have an application for C#. In this application i want to display a modal dialog box or a modal form in a thread. I have on thread running and in that...
2
by: diogenes | last post by:
I have created many shortcut/popup (aka context, or right-click) menus for my application - instead of toolbars or standard drop-down menus. Within my custom menu, I am using...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.