MFC CDialog::Domodal returns -1 with exact error 1814

I’m trying to create a UI(dialog) in an existing dll using MFC where an application is supposed to call the method which should create this dialog(this can be any application. the dialog is specific to the dll, but the method is generic across multiple dlls). I’m using DoModal method here with a CDialog inherited class and the return value of the DoModal is -1 with result of getexacterror code 1814 which is ERROR_RESOURCE_NAME_NOT_FOUND according to the microsoft documentation. Has anyone faced similar situation and guide me through it. I’ve literally tried copying from a sample app and it still wouldn’t work.

what i am trying to create is a basic empty dialog.

The code looks like this

mydlg dlg1;

int nRet = dlg1.InitDlg();
DWORD exacterror = ::GetLastError();

where the class declaration of mydlg is like:

class mydlg : public CDialog

the method InitDlg:

BOOL InitDlg()
{
CDialog::DoModal();
}

and the assertion occurs in the entry of the DoModal method while debugging.
could anyone help me with this one

Tried with a new MFC sample app and compared what I missed.
Expecting someone who faced the same issue to give a resolution and point out my mistake.

New contributor

Meow42 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

4

Resources are uniquely identified by three pieces of information:

  • The resource ID or name
  • The resource type
  • The module handle (HMODULE) identifying the module containing the resource

The resource ID is passed to CDialog‘s c’tor and the type (RT_DIALOG) is inferred by the system as the implementation calls CreateDialogIndirectParam() to construct the dialog. The module handle, however, is never passed along and MFC pulls this information out of a global state object (see Managing the State Data of MFC Modules).

By default, the global AFX_MODULE_STATE points to the executable used to start the process. This is an implementation detail as long as code and resources are linked into a single EXE. However, managing the module state becomes your responsibility as soon as you move resources into a DLL.

Thankfully, the rules are easy to follow, as explained under Exported DLL Function Entry Points:

If you have an exported function, such as one that launches a dialog box in your DLL, you need to add the following code to the beginning of the function:

AFX_MANAGE_STATE(AfxGetStaticModuleState())

This does two things:

  • It adjusts the global AFX_MODULE_STATE to point to the current module for use in future resource lookups
  • It returns an (invisible) object with automatic storage duration whose d’tor restores the previous module state

Adding this piece of code to the beginning of every function exported from the DLL that (directly or indirectly) accesses resources solves the issue of resource lookup failures.

Full details on the internals are available here: TN058: MFC Module State Implementation.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật