|
|
I have a regular DLL that uses MFC statically linked.
When I try to export a function with a c-style unmangled name, the DLL ends up being built with a mangled name for the function.
The function I'm exporting is defined as follows:
extern "C"
{
_declspec(dllexport) _LaunchProcess __stdcall Start(LPCLIENT32STARTUPCONTEXT StartupContext)
{
theApp.Start(StartupContext);
return &LaunchProcess;
}
}
When I build the DLL, the function ends up named "_Start@4" instead of just "Start". Does anyone know how I can force it to export the function as "Start"?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
|
I'll try it, thanks.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
It worked, thank you.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
The MSDN documentation describes this - dllexport, dllimport[^]
Here is the excerpt from the documentation -
dllexport of a function exposes the function with its decorated name. For C++ functions, this includes name mangling. For C functions or functions that are declared as extern "C", this includes platform-specific decoration that's based on the calling convention. If you don't want name decoration, use a .def file (EXPORTS keyword).
Here is the result of what I tried with dllexport -
extern "C" __declspec(dllexport) void __cdecl One() {}
extern "C" __declspec(dllexport) void __stdcall Two() {}
extern "C" __declspec(dllexport) void __fastcall Three() {}
«_Superman_»
I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) (October 2009 - September 2013) Polymorphism in C
|
|
|
|
|
Oh! So it's the "__stdcall" that was causing the name mangling!
Thanks Uberman!
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Yes, but it is Microsoft specific.
If you'll always use dllimport when invoking functions in the DLL, any calling convention will work as long as it is correctly specified while importing.
«_Superman_»
I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) (October 2009 - September 2013) Polymorphism in C
|
|
|
|
|
#include "stdafx.h"
#include "DemoTest.h"
#define MAX_LOADSTRING 100
HINSTANCE hInst; TCHAR szTitle[MAX_LOADSTRING]; TCHAR szWindowClass[MAX_LOADSTRING];
GdiplusStartupInput m_gdiplusStartupInput;
ULONG_PTR m_pGdiToken;
HWND g_hWnd = 0;
Image *g_pImageBack=0;
BLENDFUNCTION g_Blend;
int g_BakWidth, g_BakHeight;
bool isMouseDown=false;
POINT mousePos;
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
void Update();
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
GdiplusStartup(&m_pGdiToken,&m_gdiplusStartupInput,NULL);
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
MSG msg;
HACCEL hAccelTable;
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_DEMOTEST, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_DEMOTEST));
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
GdiplusShutdown(m_pGdiToken);
return (int) msg.wParam;
}
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_DEMOTEST));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = MAKEINTRESOURCE(IDC_DEMOTEST);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
return RegisterClassEx(&wcex);
}
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance;
hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
g_Blend.SourceConstantAlpha = int(0 * 2.55); g_Blend.BlendOp=0; g_Blend.BlendFlags=0; g_Blend.AlphaFormat=1; g_Blend.SourceConstantAlpha=255; DWORD dwExStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
SetWindowLong(hWnd, GWL_STYLE, dwExStyle ^ WS_EX_TOOLWINDOW);
dwExStyle = ::GetWindowLong(hWnd, GWL_EXSTYLE);
g_pImageBack = Image::FromFile(_T("C:\\Users\\Cmma\\Desktop\\2.png"));
ImageType t = g_pImageBack->GetType();
g_BakWidth = g_pImageBack->GetWidth();
g_BakHeight = g_pImageBack->GetHeight();
g_hWnd=hWnd;
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
Update();
return TRUE;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_LBUTTONDOWN:
isMouseDown=true;
GetCursorPos(&mousePos);
ScreenToClient(hWnd,&mousePos);
break;
case WM_MOUSEMOVE:
if(isMouseDown)
{
hdc=::GetDC(hWnd);
Graphics g(hdc);
Pen pen(RGB(255,0,0),3);
g.DrawLine(&pen,0,0,100,100);
::ReleaseDC(hWnd,hdc);
SendMessage(hWnd,WM_PAINT,0,0);
}
break;
case WM_LBUTTONUP:
isMouseDown=false;
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
Update();
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
return (INT_PTR)TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;
}
void Update()
{
HDC hdcTemp= ::GetDC(g_hWnd);
HDC hdcMemory=CreateCompatibleDC(hdcTemp);
HBITMAP hBitMap=CreateCompatibleBitmap(hdcTemp, g_BakWidth, g_BakHeight);
SelectObject(hdcMemory, hBitMap);
HDC hdcScreen=::GetDC (g_hWnd);
RECT rct;
::GetWindowRect(g_hWnd, &rct);
POINT ptWinPos={rct.left,rct.top};
Graphics graph(hdcMemory);
Point points[] = { Point(0, 0),
Point(g_BakWidth, 0),
Point(0, g_BakHeight)
};
graph.DrawImage(g_pImageBack, points, 3);
POINT ptDst;
ptDst.x = rct.left;
ptDst.y = rct.top;
SIZE size={g_BakWidth, g_BakHeight};
POINT pt;
pt.x = 0;
pt.y = 0;
DWORD dwExStyle = GetWindowLong(g_hWnd,GWL_EXSTYLE);
if((dwExStyle & WS_EX_LAYERED) != WS_EX_LAYERED)
{ SetWindowLong(g_hWnd, GWL_EXSTYLE,dwExStyle^WS_EX_LAYERED);
}
if (!UpdateLayeredWindow( g_hWnd, hdcScreen, &ptWinPos,
&size, hdcMemory, &pt, 0, &g_Blend, 2))
{
DWORD dwError = ::GetLastError();
printf("failed");
}
graph.ReleaseHDC(hdcMemory);
::DeleteObject(hBitMap);
::DeleteDC(hdcMemory);;
::ReleaseDC(g_hWnd, hdcTemp);
::ReleaseDC(g_hWnd, hdcScreen);
}
|
|
|
|
|
That's an awful lot of code to look through without the ability to compile and test. (You havent included the source of DemoTest.h or resource.rc)
What, specifically, is the problem you're having?
|
|
|
|
|
I want to use #ifdef in my source files to determine if I'm building a 32-bit or a 64-bit executable.
What is the macro I should look for to see if it is a x64 build?
#ifdef x64MACRO
{
64-bit code;
}
#else
{
32-bit code;
}
Thank you.
EDIT:
The answer is "_WIN64". Thanks for reading my post.
The difficult we do right away...
...the impossible takes slightly longer.
modified 22-Nov-13 17:44pm.
|
|
|
|
|
Richard Andrew x64 wrote: What is the macro I should look for to see if it is a x64 build?
Hi,
While _WIN64 will work for windows API... it would be more correct to check for _M_X64 if targeting x86-64.
Best Wishes,
-David Delaune
|
|
|
|
|
Randor wrote: if targeting x86-64
As opposed to? Do you mean ARM or Itanium?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hi,
All of the above. There are various Microsoft specific #defines you could utilize when targeting a specific platform:
Predefined Macros[^]
_M_X64 will automatically be defined by the compiler if the target platform is x64. If you are targeting Itanium _M_IA64 is defined by the compiler. etcetera...
Best Wishes,
-David Delaune
|
|
|
|
|
Hi,
I need some quick help on how to make the tree control's background as transparent.
I could achieve similar for setting the dialogbox (CDialog) as transparent.
I have researched alot on this but could-not find a working solution.
Erasebackground,OnCtlColor but they have not worked for the tree control.
Attached is a sample project where this tree control is attached.Expect tree control and the button's I am able to set the transparent dialog as shown in attached snapshot.
Request you to please help me with this issue.
Regards,
Kalyani Homkar
|
|
|
|
|
Hi,
I was unable to attach the sample, but any mfc dialog based sample we can create and add the below code along with a treeview control from resource editor to reproduce it:
OnInitDialog():
SetBackgroundColor(RGB(1,11,21));
LONG ExtendedStyle = GetWindowLong(GetSafeHwnd(),GWL_EXSTYLE );
SetWindowLong(GetSafeHwnd(),GWL_EXSTYLE,ExtendedStyle | WS_EX_LAYERED );
::SetLayeredWindowAttributes(GetSafeHwnd(),RGB(1,11,21),255,LWA_COLORKEY );
Regards,
Kalyani
|
|
|
|
|
In client program ssl_connect(),ssl_write() working fine but ssl_read() is returning SSL_ERROR_ZERO_RETURN. I can't do anything in server program because i am working in Client program.
What i have to do in client program to avoid SSL_ERROR_ZERO_RETURN
error from ssl_read() ?
|
|
|
|
|
Member 10413752 wrote: What i have to do in client program to avoid SSL_ERROR_ZERO_RETURN error from ssl_read() ? Since SSL_ERROR_ZERO_RETURN resvoles to 6 , that means that SSL_read() read 6 bytes from the SSL/TLS connection. Perhaps you meant instead that SSL_get_error() returned SSL_ERROR_ZERO_RETURN .
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Hello there,
I am developing an app with CDHtmlDialog that will have a user interface developed in HTML and JavaScript (JS) and CSS.
I am able to make calls from my C++ code to JS. But not sure how i can make calls from JS to C++ code.
Can anyone tell me how to do that?
Any sample code will help.
Thanks in advance.
|
|
|
|
|
I actually want some kind of tool for static analysis of the code, like checkstyle in JAVA.
What i mean by static analysis is, it tells you the coding style error, unused variable and function names
|
|
|
|
|
|
I go though that and go though the websites of few tools, however I didn't find what I am looking for.
I downloaded and configure cppcheck however it doesn't show any style report ( if braces are placed wrong or that kind of errors)
|
|
|
|
|
Well, we use Klocwork[^] at work - It is great for C++, and finds memory leaks, unused variables and so on.
Veni, vidi, caecus
|
|
|
|
|
I did a very lengthy evaluation of static analysis tools at my last job. In summary, cppcheck is pretty good and since it's free, why not. Of the paid tools, PVS-Studio was one of the best and very reasonably priced (not any more!) and rather expensive, but not as much as other tools (Unfortunately, instead of just listing a price, they play games with you, which means I really can't recommend them anymore--any company too chickenshit to put up plain prices doesn't deserve my business.) Of the super-expensive tools, the best, by a huge margin, was Coverity. It found almost all of the known issues, several critical issues none of the other tools found and almost three dozen minor issues. They are expensive, but worlds better than Klocwork and Parasoft.
Parasoft was pretty bad--their analysis tool did better than Klocwork, but missed several issues cppcheck caught and missed several known critical errors. Their product is excruciating slow and Parasoft's other tools were a disaster--several wouldn't even run. Klocwork was very buggy, missed several known bugs and their support was offensively useless (the evaluation went so badly that we terminated it early.)
One thing I concluded is that Parasoft and Klocwork specialize in selling to companies which must comply with weird rules for government work (for which there are hundreds of rules, like how switch statements must operate.) They do well at that, but not so well in finding actual bugs.
(Riverblade Software which makes Visual Lint, a tool which helps you deal with PC-Lint and Cppcheck--I don't much like it, but you may.)
modified 22-Nov-13 13:00pm.
|
|
|
|
|
Interesting you mentioned Parasoft: a couple of years ago (at a time when it was still relatively cheap) I chose it over lots of others based on a comparison report (which I unfortunately cannot locate any more). Back then it was indicated to be one of the best tools available for the Windows platform (the best affordable one at least), and indeed we got very good results.
That said, like what you stated about PVS, they don't openly state their prices, and now they're much more expensive than they used to be. Unfortunately this seems to be common practice for software tool makers nowadays Good thing there is open source! But still a pain when you really need to find the best tool for the job and end up wasting hours with inquiries only to find out the price tags are way beyond sanity!
Note however that Parasoft does instrument code for runtime analysis too, and we could uncover a number of very nasty memory leaks and bugs that we wouldn't have found in years without a tool, and not at all with static analysis alone! It's true they're not really great at static analysis, but that was never our main concern to start with!
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|