Visual c++ 使用g+进行精细编译+;但Visual Studio 2015失败了 我对VisualStudio 2015、C++、宏有一个令人困惑的问题。我在后台确实有一个更大的项目,但下面的玩具示例说明了这个问题 我有下面的C++代码(OMA8RC,OMA8. H,OMA8.CPP)来创建一个玩具对话框。它可以很好地使用gcc编译器进行编译:

Visual c++ 使用g+进行精细编译+;但Visual Studio 2015失败了 我对VisualStudio 2015、C++、宏有一个令人困惑的问题。我在后台确实有一个更大的项目,但下面的玩具示例说明了这个问题 我有下面的C++代码(OMA8RC,OMA8. H,OMA8.CPP)来创建一个玩具对话框。它可以很好地使用gcc编译器进行编译:,visual-c++,dialog,macros,Visual C++,Dialog,Macros,windres-O coff-i oma8.rc-O oma8.res g++oma8.cpp oma8.res-o oma8 // oma8.cpp #include <windows.h> #include <iostream> #include <iomanip> #include <string> #include <stdio.h> #include "stdlib.h" #include "oma8.h" using na

windres-O coff-i oma8.rc-O oma8.res
g++oma8.cpp oma8.res-o oma8

// oma8.cpp
#include <windows.h>
#include <iostream>
#include <iomanip>
#include <string>
#include <stdio.h>
#include "stdlib.h"
#include "oma8.h"

using namespace std;

string param2;
int b1, b3;

string GetInputText( HWND dlg, int resid  ) {
HWND hc = GetDlgItem( dlg, resid );
int n = GetWindowTextLength( hc ) + 1;
string s( n, 0 );
GetWindowText( hc, &s[0], n );
  return s;
}

int GetCheck( HWND dlg, int resid) {
HWND hc = GetDlgItem(dlg,resid);
int n = IsDlgButtonChecked( dlg, resid);
return n;
}

BOOL CALLBACK DialogProc( HWND hwnd, UINT message,
                       WPARAM wp, LPARAM  ) {
  switch ( message ) {
    case WM_COMMAND:  {
      int ctrl = LOWORD( wp );
      int event = HIWORD( wp );        
      if ( ctrl == IDCANCEL && event == BN_CLICKED  ) {
        DestroyWindow (hwnd);
        return TRUE;     
      } 
      else if ( ctrl == IDOK && event == BN_CLICKED ) { 
    param2 = GetInputText( hwnd, IDC_EDIT1 );
    b1 = GetCheck( hwnd, RB1 );
    b3 = GetCheck( hwnd, RB3 );  // ignore the other buttons for now
    DestroyWindow (hwnd);
    return TRUE;     
      } 
      return FALSE; 
    }
    case WM_DESTROY:         
      PostQuitMessage(0);         
      return TRUE;
    case WM_CLOSE:
      DestroyWindow (hwnd);
      return TRUE;     
  }

  return FALSE;
}

int main() {

HWND dlg = CreateDialog(  GetModuleHandle(0),
                        MAKEINTRESOURCE( IDD_DIALOG1 ), 
                        0, DialogProc );
MSG msg;

while ( GetMessage( & msg, 0, 0, 0 ) ) {
    if ( ! IsDialogMessage( dlg, & msg ) ) {
        TranslateMessage( & msg );
        DispatchMessage( & msg );
    }
}

cout << "corner text: " << param2 << " as a number: " << atof(&param2[0]) << endl;
cout << "radio1: " << b1 << " radio3: " << b3 << endl;
}

// oma8.rc (stripped 3 comment lines from start)
#include <windows.h> 
#include "oma8.h"

//#include "winresrc.h"  // apparently not needed

LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL

IDD_DIALOG1 DIALOG 20, 20, TABNR(8), THISLINEHEIGHT(15) 
STYLE DS_3DLOOK | DS_SETFONT | WS_CAPTION | WS_SYSMENU | WS_VISIBLE | WS_SIZEBOX
//STYLE DS_CENTER | DS_SHELLFONT | DS_FIXEDSYS | DS_MODALFRAME | WS_VSCROLL | WS_POPUP
CAPTION "Caption here"
FONT 10, "Arial"
{
LTEXT           "Corner text",IDC_STATIC,LMARG,UPMARG,60,RHEIGHT
EDITTEXT        IDC_EDIT1, 60, UPMARG, 60,FIELDH, ES_AUTOHSCROLL
DEFPUSHBUTTON   "OK",IDOK,TABNR(5),UPMARG,TABW,FIELDH
PUSHBUTTON      "Cancel",IDCANCEL,TABNR(6),UPMARG,TABW,FIELDH
LTEXT           "Block1, line 1",IDC_STATIC,TABNR(RBCOLUMN),THISLINEHEIGHT(PARAMLINE),TEXTW,RHEIGHT
AUTORADIOBUTTON "B1, line 2",RB1,TABNR(RBCOLUMN),THISLINEHEIGHT(PARAMLINE+1),TEXTW,RHEIGHT,WS_GROUP
AUTORADIOBUTTON "B1, line 3",RB2,TABNR(RBCOLUMN),THISLINEHEIGHT(PARAMLINE+2),TEXTW,RHEIGHT
LTEXT           "Block2 col 1",IDC_STATIC,TABNR(SNGLCOLUMN),THISLINEHEIGHT(CHOICELINE),TABW,RHEIGHT
AUTORADIOBUTTON "B2 col 2",RB3,TABNR(SNGLCOLUMN+1),THISLINEHEIGHT(CHOICELINE),TABW,RHEIGHT, WS_GROUP
AUTORADIOBUTTON "B2 col 3",RB4,TABNR(SNGLCOLUMN+2),THISLINEHEIGHT(CHOICELINE),TABW,RHEIGHT
LTEXT           "Block3, line 1",IDC_STATIC,TABNR(RANGECOLUMN),THISLINEHEIGHT(TXLINE),TEXTW,RHEIGHT
AUTORADIOBUTTON "B3, line 2",RB5,TABNR(RANGECOLUMN),THISLINEHEIGHT(RXLINE),TEXTW,RHEIGHT,WS_GROUP
AUTORADIOBUTTON "B3, line 3",RB6,TABNR(RANGECOLUMN),THISLINEHEIGHT(SCLINE),TEXTW,RHEIGHT
}

// oma8.h (stripped 2 comment lines from start)
#define IDD_DIALOG1     100

// basic buttons
#ifndef IDC_STATIC
#define IDC_STATIC (-1)
#endif
#ifndef IDOK
#define IDOK        40000
#endif
#ifndef IDCANCEL
#define IDCANCEL    40001
#endif

// measures
#define LMARG       6
#define UPMARG      5
#define TEXTW       120 // rb text width
#define TABW        50  // tab width
#define FIELDW      30  // fill-in field w
#define FIELDH      13  // fill-in field h
#define RHEIGHT     14  // row height

// line numbers
#define PARAMLINE       2
#define NOFPARAMS       2
#define OFFSET2         2
#define OFFSET3         5
#define CHOICELINE      (PARAMLINE+NOFPARAMS+OFFSET2)
#define TXLINE          (CHOICELINE+1)
#define RXLINE          (CHOICELINE+2)
#define SCLINE          (CHOICELINE+3)
#define RANGETITLELINE  2
#define RANGEFIELDLINE  (RANGETITLELINE+1)
#define DETECTORLINE    (CHOICELINE+OFFSET3)
#define THISLINEHEIGHT(x)   (UPMARG+(x)*RHEIGHT)

// column numbers
#define TABNR(x)        (LMARG+TABW*(x))
#define RBCOLUMN        1
#define RANGECOLUMN     5
#define SNGLCOLUMN      2
#define DTCTCOLUMN      7

// parameter buttons
#define IDC_EDIT1       1002
#define RB1             1010
#define RB2             1011
#define RB3             1012
#define RB4             1013
#define RB5             1014
#define RB6             1015
进入

我只收到一条错误消息:

错误RC2104未定义的关键字或密钥名称:*oma8.rc 11

我的链接器/编译器选项一定很有趣吧?当从现有代码将其创建为项目时,我选择了Console App,并将所有其他选项保留为默认值。(对不起,我记不起是什么了,只是有很多首字母缩略词。)

我花了一个多星期的时间在谷歌上搜索和尝试不同的修改,但一直没能解决这个问题。我不知道还能尝试什么。我应该去哪里调查?欢迎提出任何意见和进一步的问题


我的系统是Win7,64位。G+版本表示G++(TMM-1)5.1.0(C)2015自由软件基金会< /P>编译器不能评估表达式。代码>对话框20、20、100、100是有效的语句<代码>对话框20,20,(6+50*(8)),(5+(15)*14)不是-但后者是宏生成的。谢谢,这就可以解释了。但这是真的吗?VS2015应该根据理解宏。是的,RC编译器确实“理解”宏。它不了解扩展这些宏的结果。计算表达式的不是预处理器:扩展的结果,例如,
TABNR(8)
(6+50*(8))
,而不是
406
。预处理器只执行简单的文本替换。这让我很惊讶,我一直认为预处理器会计算表达式。至少gcc/windres中的一个是这样的。你应该把你的回答变成一个“答案”,这样我才能把它标记为正确的答案,你会得到应得的荣誉。:-)区别不在于预处理器,而在于编译器本身。我很确定windres编译器本身,而不是预处理器,知道如何计算,而微软的RC编译器不知道。很容易测试:取出一个
TABNR(8)
,并手动将其替换为
(6+50*(8))
(因此您有一个预处理器没有涉及的表达式)。我预测windres仍然会接受它,RC仍然会被它扼杀。
#define THISLINEHEIGHT(x)   (UPMARG+(x)*RHEIGHT)
#define TABNR(x)        (LMARG+TABW*(x))
#define THISLINEHEIGHT(x)   (UPMARG + (x) * RHEIGHT)
#define TABNR(x)        (LMARG + TABW * (x))