Error C4439 'main' : function definition with a managed type in the signature must ha

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Soorali
    New Member
    • Jul 2010
    • 5

    Error C4439 'main' : function definition with a managed type in the signature must ha

    Hi

    I am a newbie to VC++ and this is my first independent project so please pardon my ignorance!!

    My project compiles and runs perfectly fine in Debug mode.

    However, when I try to compile it in Release mode ( I need this to use the Setup wizard for application Deployment) I get the following error:
    error C4439: 'main' : function definition with a managed type in the signature must have a __clrcall calling convention

    I am using the following parameters:

    Calling Convention : _stdcall (/Gz)

    Common Language Runtime Support (/clr)

    I have also added the library file ole32.lib in the Additional Dependancies in the Project Property.

    When I try to use :

    Code:
    [I]int __clrcall main(array<System::String ^> ^args)[/I]
    I get the following Link errors:
    error LNK2001: unresolved external symbol "extern "C" void __stdcall HidD_GetHidGuid (struct _GUID *)" (?HidD_GetHidGu id@@$$J14YGXPAU _GUID@@@Z)

    1>GUI.obj : error LNK2001: unresolved external symbol "extern "C" void * __stdcall SetupDiGetClass DevsA(struct _GUID const *,char const *,struct HWND__ *,unsigned long)" (?SetupDiGetCla ssDevsA@@$$J216 YGPAXPBU_GUID@@ PBDPAUHWND__@@K @Z)

    1>GUI.obj : error LNK2001: unresolved external symbol "extern "C" int __stdcall SetupDiEnumDevi ceInterfaces(vo id *,struct _SP_DEVINFO_DAT A *,struct _GUID const *,unsigned long,struct _SP_DEVICE_INTE RFACE_DATA *)" (?SetupDiEnumDe viceInterfaces@ @$$J220YGHPAXPA U_SP_DEVINFO_DA TA@@PBU_GUID@@K PAU_SP_DEVICE_I NTERFACE_DATA@@ @Z)

    1>GUI.obj : error LNK2001: unresolved external symbol "extern "C" int __stdcall SetupDiGetDevic eInterfaceDetai lA(void *,struct _SP_DEVICE_INTE RFACE_DATA *,struct _SP_DEVICE_INTE RFACE_DETAIL_DA TA_A *,unsigned long,unsigned long *,struct _SP_DEVINFO_DAT A *)" (?SetupDiGetDev iceInterfaceDet ailA@@$$J224YGH PAXPAU_SP_DEVIC E_INTERFACE_DAT A@@PAU_SP_DEVIC E_INTERFACE_DET AIL_DATA_A@@KPA KPAU_SP_DEVINFO _DATA@@@Z)

    1>GUI.obj : error LNK2001: unresolved external symbol "extern "C" unsigned char __stdcall HidD_GetAttribu tes(void *,struct _HIDD_ATTRIBUTE S *)" (?HidD_GetAttri butes@@$$J18YGE PAXPAU_HIDD_ATT RIBUTES@@@Z)

    1>GUI.obj : error LNK2001: unresolved external symbol "extern "C" int __stdcall SetupDiDestroyD eviceInfoList(v oid *)" (?SetupDiDestro yDeviceInfoList @@$$J14YGHPAX@Z )

    1>GUI.obj : error LNK2001: unresolved external symbol "extern "C" unsigned char __stdcall HidD_SetOutputR eport(void *,void *,unsigned long)" (?HidD_SetOutpu tReport@@$$J212 YGEPAX0K@Z)

    1>GUI.obj : error LNK2001: unresolved external symbol "extern "C" unsigned char __stdcall HidD_GetInputRe port(void *,void *,unsigned long)" (?HidD_GetInput Report@@$$J212Y GEPAX0K@Z)

    1>GUI.obj : error LNK2001: unresolved external symbol "extern "C" long __stdcall UuidCreate(stru ct _GUID *)" (?UuidCreate@@$ $J14YGJPAU_GUID @@@Z)

    1>GUI.obj : error LNK2001: unresolved external symbol "extern "C" long __stdcall UuidToStringA(s truct _GUID const *,unsigned char * *)" (?UuidToStringA @@$$J18YGJPBU_G UID@@PAPAE@Z)

    1>GUI.obj : error LNK2001: unresolved external symbol "extern "C" long __stdcall RpcStringFreeA( unsigned char * *)" (?RpcStringFree A@@$$J14YGJPAPA E@Z)

    1>C:\Documents and Settings\bandu\ My Documents\Visua l Studio 2008\Projects\1 3th July - TES GUI wshid\GUI\Relea se\GUI.exe : fatal error LNK1120: 11 unresolved externals
    Please Help!!

    Soorali
    Last edited by Niheel; Jul 21 '10, 02:12 AM.
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Are you are are you not using .NET?

    Does your project require it?

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      I have made a GUI using the Windows Form Application. On button clicks on the GUI the program sends messages via USB to a connected device. Also one of the button connects this device to Skype and interacts with it.

      Since I am using the windows Form application I THINK (in the limited knowledge I have) that I would need a .Net environment to run the .exe file.

      Please feel free to correct me if I am wrong.
      No you do not need to use .NET to create Windows programs, you can call the WIN32 API directly.

      I asked because your errors look like they may be being produced by a clash between .NET and non-.NET code.

      However I am not an expert on that.

      Comment

      • Soorali
        New Member
        • Jul 2010
        • 5

        #4
        Hi Banfa,

        Thanks for your response.

        I have checked my project properties and am using the Win32 API.

        Do you have any idea what could be causing this??

        Regards,
        Soorali

        Comment

        • Banfa
          Recognized Expert Expert
          • Feb 2006
          • 9067

          #5
          This

          Code:
          int __clrcall main(array<System::String ^> ^args)
          is the managed code version of main, you should be using either

          Code:
          int main(int argc, char* argp[])
          Or its Microsoft equivalent wide character version

          Code:
          int wmain( int argc , wchar_t *argv[]);
          Or its Microsoft equivalent that automatically selects the single or wide character version

          Code:
          int _tmain(int argc, _TCHAR* argv[])
          Using this prototype automatically selects the correct version of the previous 2.


          Another alternative is

          Code:
          int WINAPI _tWinMain(HINSTANCE hInstance,
              HINSTANCE hPrevInstance,
              LPTSTR lpCmdLine,
              int nCmdShow)
          This is the Windows entry point again the _t indicating that it automatically switches between single byte and multibyte characters. You should be using this if you are compiling as a Windows application as opposed to a console application.

          Comment

          • johny10151981
            Top Contributor
            • Jan 2010
            • 1059

            #6
            Hi,
            This answer is obsolet now :)
            cause I didnt notice Banfa described it well :)



            Hi,
            Your main function definition says, its not a GUI program
            you are doing console application.
            in console application you can define main like this
            Code:
            int main(int argc, char *argv[]);
            But if this is a graphical user interface the definition is different
            Code:
            int __stdcall WinMain(HINSTANCE hPrevInstance,
                                 LPTSTR    lpCmdLine,
                                 int       nCmdShow)
            or
            Code:
            int APIENTRY _tWinMain(HINSTANCE hInstance,
                                 HINSTANCE hPrevInstance,
                                 LPTSTR    lpCmdLine,
                                 int       nCmdShow)
            infact APIENTRY,WINAPI and __stdcall are all same
            Code:
            #define WINAPI __stdcall 
            #define APIENTRY WINAPI
            and
            Code:
            #define _tWinMain wWinMain
            wWinMain is widecharcter version of WinMain

            Let me know if my above information is wrong

            Johny
            Last edited by johny10151981; Jul 21 '10, 11:53 AM. Reason: Repeating Answer

            Comment

            • Soorali
              New Member
              • Jul 2010
              • 5

              #7
              Hi Banfa/ Johny,

              Thank you for replying to my post.

              It finally works!!!

              This is what I did:

              Changed the call to the main routine to :

              int __clrcall main(array<Syst em::String ^> ^args)

              It did not seem to like the _stdcall before main.


              Got the usual 12 Link errors with the __clrcall. Then realised the lib files were missing from the Additional Dependancies from the Project Properties. Included those and after a few hiccups it finally works!!!

              One thing I am a bit confused by....in the Project Properties it says I am using the .Net Framework but on a Win32 platform....is that why I need the __clrcall before the main???

              Let me know your thoughts please.

              Cheers
              Soorali

              Comment

              Working...