0

I want to link c++ to GAMS software using createprocess() function. I used this code but it just opens the GAMS software. I want that the programe run a file.gms automatically after openning the GAMS software:

STARTUPINFO si;    
PROCESS_INFORMATION pi;   
ZeroMemory(&si, sizeof(si));  
si.cb = sizeof(si);  
ZeroMemory(&pi, sizeof(pi));  
if(CreateProcessW(L"C:\\PROGRA~1\\gams23.3\\gamside.exe",NULL,NULL,NULL,false,0,NULL,NULL,&si,&pi))   
 {      
    WaitForSingleObject(pi.hProcess, 10000 );   
           CloseHandle( pi.hProcess );   
           CloseHandle( pi.hThread );   
 }

Please help me. Thanks so much.

Serj-Tm
  • 16,581
  • 4
  • 54
  • 61
Nahid
  • 11

2 Answers2

1

You should fill in the second parameter (LPTSTR lpCommandLine) with the command line you want to see gamside.exe (e.g. passing your file as 1st argument). What you'll need to specify there depends on the specification of the gamside program (WETF this is).

BTW: Using the term 'linking' in your questions title is a bit misleading for this topic, since 'linking' in context of C++ usually means to link a library to your executable, not to call another executable from it.

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
  • Would you mind adding a gams tag to this question and also http://stackoverflow.com/q/22666921/1470262? – Elaine Hale Jul 10 '14 at 16:20
  • @ElaineHale There's no [tag:gams] tag currently existing (and I don't want to create a new one). I'll mark the question as possible duplicate for the link you gave. – πάντα ῥεῖ Jul 10 '14 at 16:24
  • Why don't you want to create a new tag for gams? It seems appropriate since there is already an ampl one, there are at least 5-10 existing questions that could use it, and presumably adding it would make it easier for gams programmers to give and get help on StackOverflow. – Elaine Hale Jul 11 '14 at 14:59
  • Also, this question is not a duplicate of my question. I only mentioned my question as another one that could use a gams tag. – Elaine Hale Jul 11 '14 at 15:04
  • @ElaineHale I've been looking into your question that got an answer mainly dealing with the parameters that are necessary to pass to the program. The same essentially applies here. I can't create the tag, it's refused that a very similar [tag:gam] already exists, and one should ask on meta to create the new one :-/ ... – πάντα ῥεῖ Jul 11 '14 at 15:19
  • Thanks for looking into those things! I guess I will post something to meta ... – Elaine Hale Jul 11 '14 at 19:58
  • @ElaineHale De nada! The answer I gave here was from a very general POV. I don't have any expertise in [tag:gams] actually. Would you mind enlightening me what that stuff is about? [Is this the correct reference](http://www.gams.de/)? – πάντα ῥεῖ Jul 11 '14 at 20:11
  • That is the correct reference. GAMS is a language for formulating and solving optimization problems. – Elaine Hale Jul 14 '14 at 15:46
1

This general question of invoking the GAMS model solver from other programming environments is well-handled on the GAMS help pages and discussion list. See, e.g.

http://interfaces.gams-software.com/doku.php?id=env:executing_gams_from_other_environments or http://interfaces.gams-software.com/doku.php?id=env:spawning_gams_from_visual_c

You may want to invoke gams.exe rather than gamside.exe since you do not need the IDE. The calling syntax for gams.exe from the command line is well-documented.

pleiby
  • 63
  • 1
  • 3