473,729 Members | 2,409 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Creating modal dialog in vc++

31 New Member
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(dllex port) UINT __stdcall VerifyPID(MSIHA NDLE hInstall);

TCHAR* GetPIDValue(TCH AR*);

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

dwBuffer = sizeof(szSource Dir)/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_ICONEXCLAMAT ION);
return 0;
}

lpszPidValue = GetPIDValue(szS ourceDir);

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_ICONEXCLAMAT ION);
return 0;
}

int str = lstrcmp(szPidKe y, 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_ICONINFORMAT ION);
}
return 0;
}

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

Please help to resolve it.

Thanks in advance.

Regards,
Dhanasekaran. G
Apr 18 '08 #1
1 3105
weaknessforcats
9,208 Recognized Expert Moderator Expert
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
3627
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, the same frame is used -- this is done using a singleton. The user can do other stuff in the main window while the help window is up. However, when I have a modal dialog pop-up to get information from the user, it blocks events to the help...
2
6728
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 save. When I return in my first modal dialog, dropdownlist is not refreshed. I don't know how to refresh my first modal dialog to view my new element in the dropdownlist. Thanks to help me with this problem!
2
2559
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 bring up a modal dialog (MessageBox)
6
1375
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 buttons. The buttons have ids of IDOK, IDCANCEL and IDC_RENAME. All I want to do is put up this modal dialog asking the user what to do. All I care is which button he pressed. I tried using
10
2754
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 preview DIV) 2. when users close the dialog, the application receives the URL to the selected graphic. 3. the modal dialog lets the users upload a new graphic if the dialog does not present them with one they are already happy with. 4. upon uploading...
2
3684
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 dialog. To be more specific I want to have a confirmation dialog that is shown when a user clicks on a Delete button (which deletes some values from database). If Yes is pressed the delete action is processed otherwise modal dialog is closed.
0
1024
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 thread i want to display a modal dialog box or a modal form. Can anybody please help me out. Thanks
2
3515
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 =ShowMainMenu("item") in the On Action event where ShowMainMenu is a public function in frmMain, and "item" is a string mapping to a button click event. (error trapping omitted) Public Function ShowMainMenu(strItem As String) As Boolean
0
8763
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9427
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9202
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9148
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8151
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4528
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2683
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2165
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.