5

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.

Sam
  • 28,421
  • 49
  • 167
  • 247
  • Have you tried wrapping your command with a batch file? That'd make it more command-line-ish, so maybe it does the trick. – Edurne Pascual Apr 04 '11 at 12:36
  • Can you also post your Post-Build-Macro to do so? Maybe we can find the error there. – Bobby Apr 04 '11 at 12:41
  • herenvardo, I tried to put it in a cmd, to no avail :( – Sam Apr 04 '11 at 12:50
  • @Bobby, posted the post build step. – Sam Apr 04 '11 at 12:51
  • @Sam: Should work in my opinion...are there any spaces in the path? Like `editbin.exe /STACK:2097152 "$(TargetPath)"`? – Bobby Apr 04 '11 at 12:56
  • @Bobby, no spaces in the path, and I tried both ways to no avail. I even echo'd the parameter in the batch script back to me to make sure it's the right file :( – Sam Apr 04 '11 at 12:57
  • Arg, found a problem: Editbin /Stack... c:\whatever\myapp.exe does not work. Editbin /stack... myapp.exe does work. So editbin has problems using file names containing a path. Dang. – Sam Apr 04 '11 at 13:08
  • But still it does not work as post build step. Strange. – Sam Apr 04 '11 at 13:13
  • @Sam: Last thing which comes to mind is, that if you have an implicit path, that the working directory could be wrong. – Bobby Apr 04 '11 at 15:19
  • The post build step normally executes from the solution directory not the output directory - you should use `"$(TargetPath)"` instead of `app.exe` (make sure you surround the path with quotes). – Justin Apr 05 '11 at 03:39
  • @Kragen, $(TargetPath) does not work since Editbin can't handle path names. Editbin can for some reason only handle files in the working directory. – Sam Apr 05 '11 at 07:42
  • @Sam Ah - in that case have your post-build step `cd` to the output directory before executing `editbin`. – Justin Apr 05 '11 at 07:43
  • @Sam are you sure that it doesn't work - even if you put quotes around the path? – Justin Apr 05 '11 at 07:45
  • @Kragen, I tried it manually in a command line, using a path without spaces or other strange symbols, and it did not work. Does this work for you?? – Sam Apr 05 '11 at 09:31

2 Answers2

8

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.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Aah, yes, the search path was the problem!! I added the path to \vc\bin, but the other one was still missing, so it did neither work nor put out an error. – Sam Apr 05 '11 at 07:51
  • I believe it's slightly more robust to begin your post-build step with `call "$(DevEnvDir)..\..\VC\vcvarsall.bat"` . That's what I do. – ulatekh Jan 23 '17 at 22:15
-1

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.

Justin
  • 84,773
  • 49
  • 224
  • 367
Aamir
  • 14,882
  • 6
  • 45
  • 69