René's URL Explorer Experiment


Title: 64-bit DLL compiled by G++ failed to load. · Issue #108 · fancycode/MemoryModule · GitHub

Open Graph Title: 64-bit DLL compiled by G++ failed to load. · Issue #108 · fancycode/MemoryModule

X Title: 64-bit DLL compiled by G++ failed to load. · Issue #108 · fancycode/MemoryModule

Description: I have a 64-bit DLL, with this source code: #include extern "C" { __declspec(dllexport) __cdecl void Greet() { std::cout << "Hello World!" << std::endl; } __declspec(dllexport) __cdecl int addNumbers(int a, int b) { std::cout ...

Open Graph Description: I have a 64-bit DLL, with this source code: #include extern "C" { __declspec(dllexport) __cdecl void Greet() { std::cout << "Hello World!" << std::endl; } __declspec(dllexport) __cdecl i...

X Description: I have a 64-bit DLL, with this source code: #include <iostream> extern "C" { __declspec(dllexport) __cdecl void Greet() { std::cout << "Hello World!" << std::e...

Opengraph URL: https://github.com/fancycode/MemoryModule/issues/108

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"64-bit DLL compiled by G++ failed to load.","articleBody":"I have a **64-bit** DLL, with this source code:\r\n```C++\r\n#include \u003ciostream\u003e\r\n\r\nextern \"C\"\r\n{\r\n\t__declspec(dllexport) __cdecl void Greet()\r\n\t{\r\n\t\tstd::cout \u003c\u003c \"Hello World!\" \u003c\u003c std::endl;\r\n\t}\r\n\r\n\t__declspec(dllexport) __cdecl int addNumbers(int a, int b)\r\n\t{\r\n\t\tstd::cout \u003c\u003c \"Adding \" \u003c\u003c a \u003c\u003c \" and \" \u003c\u003c b \u003c\u003c \"...\" \u003c\u003c std::endl;\r\n\t\treturn a + b;\r\n\t}\r\n}\r\n```\r\nI compiled this using g++, downloadable from [here](https://github.com/brechtsanders/winlibs_mingw/releases/tag/11.1.0-12.0.0-9.0.0-r3).\r\n\u003cdetails\u003e\r\n  \u003csummary\u003eThis is my g++ version  \u003c/summary\u003e\r\ng++ (MinGW-W64 x86_64-posix-seh, built by Brecht Sanders) 11.1.0\r\nCopyright (C) 2021 Free Software Foundation, Inc.\r\nThis is free software; see the source for copying conditions.  There is NO\r\nwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\r\n\u003c/details\u003e\r\n  \r\nThis is the command I used:  \r\n```\r\ng++ SampleDll.cpp -o SampleDLL.dll --shared \r\n```\r\n\r\n# I. Attempt to load from file.\r\nI have a C source file (always compiled using `g++ Test.c MemoryModule.c -o Test.exe -D_WIN64`)\r\nand copied the whole `LoadFromFile` function from the demo to my source file:\r\n\u003cdetails\u003e\r\n  \u003csummary\u003eThe source  \u003c/summary\u003e\r\n\r\n\r\n```C++\r\nvoid LoadFromFile(void)\r\n{\r\n    addNumberProc addNumber;\r\n    HRSRC resourceInfo;\r\n    DWORD resourceSize;\r\n    LPVOID resourceData;\r\n    TCHAR buffer[100];\r\n\r\n    HINSTANCE handle = LoadLibrary(DLL_FILE);\r\n    if (handle == NULL)\r\n        return;\r\n\r\n    addNumber = (addNumberProc)GetProcAddress(handle, \"addNumbers\");\r\n    _tprintf(_T(\"From file: %d\\n\"), addNumber(1, 2));\r\n\r\n    resourceInfo = FindResource(handle, MAKEINTRESOURCE(VS_VERSION_INFO), RT_VERSION);\r\n    _tprintf(_T(\"FindResource returned 0x%p\\n\"), resourceInfo);\r\n\r\n    resourceSize = SizeofResource(handle, resourceInfo);\r\n    resourceData = LoadResource(handle, resourceInfo);\r\n    _tprintf(_T(\"Resource data: %ld bytes at 0x%p\\n\"), resourceSize, resourceData);\r\n\r\n    LoadString(handle, 1, buffer, sizeof(buffer));\r\n    _tprintf(_T(\"String1: %s\\n\"), buffer);\r\n\r\n    LoadString(handle, 20, buffer, sizeof(buffer));\r\n    _tprintf(_T(\"String2: %s\\n\"), buffer);\r\n\r\n    FreeLibrary(handle);\r\n}\r\n```\r\n\u003c/details\u003e\r\n\r\nIt loads properly:\r\n```\r\nAdding 1 and 2...\r\nFrom file: 3\r\nFindResource returned 0x0000000000000000\r\nResource data: 0 bytes at 0x0000000000000000\r\nString1:\r\nString2: \r\n```\r\n\r\n# II. Attempt to load from Memory\r\nI also copied the `LoadFromMemory` and the `ReadLibrary` function:\r\n\u003cdetails\u003e\r\n  \u003csummary\u003eThe source  \u003c/summary\u003e\r\n\r\n\r\n```C++\r\nvoid* ReadLibrary(size_t* pSize) {\r\n    size_t read;\r\n    void* result;\r\n    FILE* fp;\r\n\r\n    fp = _tfopen(DLL_FILE, _T(\"rb\"));\r\n    if (fp == NULL)\r\n    {\r\n        _tprintf(_T(\"Can't open DLL file \\\"%s\\\".\"), DLL_FILE);\r\n        return NULL;\r\n    }\r\n\r\n    fseek(fp, 0, SEEK_END);\r\n    *pSize = (size_t)(ftell(fp));\r\n    if (*pSize == 0)\r\n    {\r\n        fclose(fp);\r\n        return NULL;\r\n    }\r\n\r\n    result = (unsigned char *)malloc(*pSize);\r\n    if (result == NULL)\r\n    {\r\n        return NULL;\r\n    }\r\n\r\n    fseek(fp, 0, SEEK_SET);\r\n    read = fread(result, 1, *pSize, fp);\r\n    fclose(fp);\r\n    if (read != *pSize)\r\n    {\r\n        free(result);\r\n        return NULL;\r\n    }\r\n\r\n    return result;\r\n}\r\n\r\nvoid LoadFromMemory(void)\r\n{\r\n    void *data;\r\n    size_t size;\r\n    HMEMORYMODULE handle;\r\n    addNumberProc addNumber;\r\n    HMEMORYRSRC resourceInfo;\r\n    DWORD resourceSize;\r\n    LPVOID resourceData;\r\n    TCHAR buffer[100];\r\n\r\n    data = ReadLibrary(\u0026size);\r\n    if (data == NULL)\r\n    {\r\n        return;\r\n    }\r\n\r\n    handle = MemoryLoadLibrary(data, size);\r\n\r\n    if (handle == NULL)\r\n    {\r\n\t\t_tprintf(_T(\"%i\"), GetLastError());\r\n        _tprintf(_T(\"Can't load library from memory.\\n\"));\r\n        goto exit;\r\n    }\r\n\r\n    addNumber = (addNumberProc)MemoryGetProcAddress(handle, \"addNumbers\");\r\n    _tprintf(_T(\"From memory: %d\\n\"), addNumber(66, 99));\r\n\r\n    resourceInfo = MemoryFindResource(handle, MAKEINTRESOURCE(VS_VERSION_INFO), RT_VERSION);\r\n    _tprintf(_T(\"MemoryFindResource returned 0x%p\\n\"), resourceInfo);\r\n\r\n    resourceSize = MemorySizeofResource(handle, resourceInfo);\r\n    resourceData = MemoryLoadResource(handle, resourceInfo);\r\n    _tprintf(_T(\"Memory resource data: %ld bytes at 0x%p\\n\"), resourceSize, resourceData);\r\n\r\n    MemoryLoadString(handle, 1, buffer, sizeof(buffer));\r\n    _tprintf(_T(\"String1: %s\\n\"), buffer);\r\n\r\n    MemoryLoadString(handle, 20, buffer, sizeof(buffer));\r\n    _tprintf(_T(\"String2: %s\\n\"), buffer);\r\n\r\n    MemoryFreeLibrary(handle);\r\n\r\nexit:\r\n    free(data);\r\n}\r\n```\r\n\u003c/details\u003e\r\n\r\nThis time, the test program failed, with an access violation.\r\n\r\n# III. Attempt to use C#'s P/Invoke:\r\nIt just works, using a basic `DllImport` attribute.\r\n\r\n# IV. Attempt to use a translated MemoryModule version, from a managed executable:\r\nFails, for the same reason.\r\n\r\n# V. Some more stuff.\r\nAfter using a C# debugger on the translated version, and various `printf` debugging on the original library, I found [this line of code](https://github.com/fancycode/MemoryModule/blob/master/MemoryModule.c#L744)'s the culprit:\r\n\r\n```\r\n            BOOL successfull = (*DllEntry)((HINSTANCE)code, DLL_PROCESS_ATTACH, 0);\r\n```\r\nThe access violation happened right after calling the dll entry point, and not because of a null pointer.\r\n\r\n# TL;DR\r\n- I have a C++ dll, **64-bit**, compiled using **G++ on MinGW-w64**, which is perfectly valid (`P/Invoke`-able, and `LoadLibrary`-able).\r\n- Loading it using MemoryModule gives an Access Violation error when trying to call the dll entry point.\r\n- Any other dll's (Compiled using MSVC (64-bit, or 32-bit), or using the lesser-known Orange C compiler (32-bit only)) works normally on MemoryModule.\r\n\r\nI do not have any experience with such low level programming, please help me explain why MemoryModule crashed when calling this entry point. Thanks in advance.","author":{"url":"https://github.com/trungnt2910","@type":"Person","name":"trungnt2910"},"datePublished":"2021-08-24T14:27:56.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/108/MemoryModule/issues/108"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:0f360c51-cb28-dcb6-af43-67818892d1f3
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idBE9A:12A9E6:345AC2:4A98D4:696F54C4
html-safe-nonced01f66e44227aaea6920babbdfc3de266700d045a2340950fae26c3b7fc4cc40
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRTlBOjEyQTlFNjozNDVBQzI6NEE5OEQ0OjY5NkY1NEM0IiwidmlzaXRvcl9pZCI6IjU3NDQxNjI5NjA3ODMxMzU5NDAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac1c2dc41758922d8967d4d8bc72c10a13cf63ec8081db817e37ca8cf6b4e81ab8
hovercard-subject-tagissue:978162295
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/fancycode/MemoryModule/108/issue_layout
twitter:imagehttps://opengraph.githubassets.com/19cf2a8dc2509a9470cfb14cb7976c5b56de0eac884baa5bec972c8cd9dda1f8/fancycode/MemoryModule/issues/108
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/19cf2a8dc2509a9470cfb14cb7976c5b56de0eac884baa5bec972c8cd9dda1f8/fancycode/MemoryModule/issues/108
og:image:altI have a 64-bit DLL, with this source code: #include extern "C" { __declspec(dllexport) __cdecl void Greet() { std::cout << "Hello World!" << std::endl; } __declspec(dllexport) __cdecl i...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernametrungnt2910
hostnamegithub.com
expected-hostnamegithub.com
None49bb2ee76ae1b4ec758faefafda636ff20b05a9708bb290d28422cdf542ae979
turbo-cache-controlno-preview
go-importgithub.com/fancycode/MemoryModule git https://github.com/fancycode/MemoryModule.git
octolytics-dimension-user_id247730
octolytics-dimension-user_loginfancycode
octolytics-dimension-repository_id1018522
octolytics-dimension-repository_nwofancycode/MemoryModule
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id1018522
octolytics-dimension-repository_network_root_nwofancycode/MemoryModule
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release036f37fe552777ac9c6ee661957f947285aab936
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/fancycode/MemoryModule/issues/108#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Ffancycode%2FMemoryModule%2Fissues%2F108
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Ffancycode%2FMemoryModule%2Fissues%2F108
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=fancycode%2FMemoryModule
Reloadhttps://github.com/fancycode/MemoryModule/issues/108
Reloadhttps://github.com/fancycode/MemoryModule/issues/108
Reloadhttps://github.com/fancycode/MemoryModule/issues/108
fancycode https://github.com/fancycode
MemoryModulehttps://github.com/fancycode/MemoryModule
Notifications https://github.com/login?return_to=%2Ffancycode%2FMemoryModule
Fork 806 https://github.com/login?return_to=%2Ffancycode%2FMemoryModule
Star 3.1k https://github.com/login?return_to=%2Ffancycode%2FMemoryModule
Code https://github.com/fancycode/MemoryModule
Issues 48 https://github.com/fancycode/MemoryModule/issues
Pull requests 9 https://github.com/fancycode/MemoryModule/pulls
Actions https://github.com/fancycode/MemoryModule/actions
Projects 0 https://github.com/fancycode/MemoryModule/projects
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/fancycode/MemoryModule/security
Please reload this pagehttps://github.com/fancycode/MemoryModule/issues/108
Insights https://github.com/fancycode/MemoryModule/pulse
Code https://github.com/fancycode/MemoryModule
Issues https://github.com/fancycode/MemoryModule/issues
Pull requests https://github.com/fancycode/MemoryModule/pulls
Actions https://github.com/fancycode/MemoryModule/actions
Projects https://github.com/fancycode/MemoryModule/projects
Security https://github.com/fancycode/MemoryModule/security
Insights https://github.com/fancycode/MemoryModule/pulse
New issuehttps://github.com/login?return_to=https://github.com/fancycode/MemoryModule/issues/108
New issuehttps://github.com/login?return_to=https://github.com/fancycode/MemoryModule/issues/108
64-bit DLL compiled by G++ failed to load.https://github.com/fancycode/MemoryModule/issues/108#top
https://github.com/trungnt2910
https://github.com/trungnt2910
trungnt2910https://github.com/trungnt2910
on Aug 24, 2021https://github.com/fancycode/MemoryModule/issues/108#issue-978162295
herehttps://github.com/brechtsanders/winlibs_mingw/releases/tag/11.1.0-12.0.0-9.0.0-r3
this line of codehttps://github.com/fancycode/MemoryModule/blob/master/MemoryModule.c#L744
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.