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
1 3105
Your code works for me after I changed it this way: -
void __stdcall DisplayFromDll()
-
{
-
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);
-
-
}
-
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: -
;BEGIN ADLL.DEF FILE
-
;This DEF file is required becuase the argument to GetProcAddress()
-
;for the function is a C-string and it will never be equal to the
-
;C++ mangled name for the function
-
;This DEF file maps the mangled name to a name that can be used with GetProcAddress()
-
;Note also: Change project settings in Visual Studio to send the LINK this def file.
-
;Visual Studio.NET: Project Properties/Linker/Input/Module Definition File/...Path to the def file\Adll.def
-
LIBRARY ADll
-
EXPORTS
-
;Exported Name C++ Mangled Name
-
DisplayFromDll = ?DisplayFromDll@@YGXXZ
-
;END DEF FILE
-
Next, be certain to set the path to the DEF file in the linker input project property.
Finally, I called the funciton: -
//First, load the dll into memory
-
HMODULE theDll = LoadLibrary(TEXT("C:\\Scratch\\Instructor\\Debug\\DLLExample.dll"));
-
if (!theDll)
-
{
-
MessageBox(NULL, TEXT("Dll Failed to Load"), TEXT("Fatal Error"), MB_OK | MB_ICONEXCLAMATION);
-
return 1;
-
}
-
-
//Second, get the address of the desried function from the dll
-
FARPROC addr = GetProcAddress(theDll, "DisplayFromDll");
-
if (!addr)
-
{
-
-
//Look up the error in the system errors list
-
unsigned int what = GetLastError();
-
if (what == ERROR_PROC_NOT_FOUND)
-
{
-
MessageBox(NULL, TEXT("Function not found in the dll"), TEXT("Fatal Error"), MB_OK | MB_ICONEXCLAMATION);
-
-
}
-
return 2;
-
}
-
cout << "The function has been located in the dll" << endl;
-
//Declare a function pointer that can accept the address of the function.
-
//You will need to know the function prototype to do this.
-
//Dll function prototypes should be provided by the vendor of the dll
-
void (__stdcall *DisplayFromDll)();
-
//Type-cast the address returned from GetProcAddress to the function pointer type
-
DisplayFromDll = reinterpret_cast<void (__stdcall *)()> (addr);
-
//Now use the function pointer to call the function:
-
DisplayFromDll();
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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!
|
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)
|
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
|
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...
| |
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.
|
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
|
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
|
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,...
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |