Stack overflow in c# app using c++ dll

2019-04-09 09:35发布

问题:

I've got a c# program which is using a c++/cli managed dll. The dll contains a lot of legacy code, consisting of quite a few win32 windows.

Problem is, the windows in the dll need a bit more stackspace than average cough. Since these are not background processes but win32 api I need to enlarge the stack size of the GUI thread (at least I think the win32 api in the dll will use the main gui process).

So I need a way to enlarge the size of the GUI thread in a c# process.

Since I found no settings to achieve this I tried editbin /STACK from the command line, which works. Problem is, it only works in the command line, if I try to enter it as post-build-step for some reason the stack size of the binary does not change, even though the postbuild step is properly executed and throws no error :(

editbin.exe /STACK:2097152 $(TargetPath)

(Editbin.exe is in the path, and there is no error in the output window)

So how do I get more stack size for my c++ dll?

[Update]

I noticed a problem using editbin.exe.

This does not work, neither in command line nor as post build step:

editbin.exe /STACK:2097152 c:\some\path\bin\release\app.exe

This does work in command line, but not as build step:

editbin.exe /STACK:2097152 app.exe

But I need it to work as post build step. I tried to put it into a batch file, echo'd to make sure call and working dir are ok, but still it does not work. Strange.

回答1:

This shouldn't work, odd that you don't get a build error. The path isn't set correctly to be able to use the tool in a C# build. It does work from the command line, the Visual Studio Command Prompt uses the config for a C/C++ project. This post-build command worked properly in VS2008:

set path=%path%;$(DevEnvDir);$(DevEnvDir)..\..\vc\bin
editbin.exe /STACK:2097152 "$(TargetPath)"

Also note the double-quotes around the target path macro to deal with spaces.



回答2:

Does this help? /F (Set Stack Size)

This is basically providing the /F switch along with the number of bytes you want to reserve for stack.