dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13

Thread: wcout compile error

Hybrid View

  1. #1
    Join Date
    May 2015
    Posts
    213

    wcout compile error

    Hello,

    Whats wrong with the std::cout in the following simple program..

    Code:
    typedef std::vector<std::wstring> (*FNPTR)();
    
    
    	HINSTANCE hInst = LoadLibrary(L"VeloxPropagationModels.dll");
    	FNPTR fn = (FNPTR)GetProcAddress(hInst, "getAvailablePropagationModelIDs");
    
    	std::vector<std::wstring> propIds = fn();
    
    	for (auto & pId : propIds)
    	{
    	std::wcout << pId;
    	}

  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,544

    Re: wcout compile error

    Do you get a compile error message? Could you provide this?
    Victor Nijegorodov

  3. #3
    Join Date
    May 2015
    Posts
    213

    Re: wcout compile error

    1>------ Build started: Project: ConsoleApplication2, Configuration: Debug x64 ------
    1> ConsoleApplication2.cpp
    1>f:\veloxpropagationmodel\wrapper\consoleapplication2\consoleapplication2.cpp(29): error C2679: binary '<<': no operator found which takes a right-hand operand of type 'std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>>' (or there is no acceptable conversion)

  4. #4
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,901

    Re: wcout compile error

    Quote Originally Posted by pdk5 View Post
    1>------ Build started: Project: ConsoleApplication2, Configuration: Debug x64 ------
    1> ConsoleApplication2.cpp
    1>f:\veloxpropagationmodel\wrapper\consoleapplication2\consoleapplication2.cpp(29): error C2679: binary '<<': no operator found which takes a right-hand operand of type 'std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>>' (or there is no acceptable conversion)
    This test code compiles OK under VS:

    Code:
    #include <iostream>
    #include <string>
    #include <vector>
    using namespace std;
    
    int main()
    {
    	vector<wstring> wstr {L"abd", L"def", L"efg"};
    
    	for (auto& w : wstr)
    		wcout << w << endl;
    }
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.3.9)

  5. #5
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,544

    Re: wcout compile error

    Did you put all the necessary #includes?
    Victor Nijegorodov

  6. #6
    Join Date
    May 2015
    Posts
    213

    Re: wcout compile error

    Yes I have included all the header files.

    Tried to debug further, that the other issue is library is not loaded properly.

    the hInstance is showing
    hInst 0x00007ffc1a700000 {VeloxPropogationModels.dll!_IMAGE_DOS_HEADER__Image_Base}{unused=9460301}

    Any help is much appreciated

  7. #7
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,544

    Re: wcout compile error

    Quote Originally Posted by pdk5 View Post
    ... the other issue is library is not loaded properly.

    the hInstance is showing
    hInst 0x00007ffc1a700000 {VeloxPropogationModels.dll!_IMAGE_DOS_HEADER__Image_Base}{unused=9460301}
    Why do you think it "is not loaded properly"? From MSDN:
    Return Value
    If the function succeeds, the return value is a handle to the module.

    If the function fails, the return value is NULL. To get extended error information, call GetLastError.
    Yu got the non-NULL value, so the LoadLibrary succeeded.

    Maybe the GetProcAddress failed (it it returned NULL)? Then call GetLastError to get extended error info.
    Victor Nijegorodov

  8. #8
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,901

    Re: wcout compile error

    When calling a Windows API function, you must always check the return value for an error condition. The documentation for each API describes this. This is done for every call. The API documentation will state the return value of the function if the function fails, and also how to get additional details. This may be from the return value itself or from GetLastError() or other stated means. Also note, that to get a description of any error codes, from within VS you can use Tools/Error Lookup.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.3.9)

  9. #9
    Join Date
    May 2015
    Posts
    213

    Re: wcout compile error

    Thanks a lot kaud for all the help.

    I think, i am missing something, when i am trying to use the package from thirdparty.

    As they have three directories, one containing the library and another module lib and another containing the module files.

    I was thinking i can statically link module lib. But it looks like it is not correct.

    I want to call the GetAvailablePropagationModels function.

    But this function is in
    Interface-Definition\Dll.h : __declspec(dllexport) void GetAvailablePropagationModels(BSTR* modelList);
    VeloxPropModels\VeloxPropModelsLib\Interface\Dll.cpp : __declspec(dllexport) void GetAvailablePropagationModels(BSTR* modelList)
    VeloxPropModels\VeloxPropModelsLib\Interface\Dll.h : __declspec(dllexport) void GetAvailablePropagationModels(BSTR* modelList);

    I think, from this search, it looks like I can only do the Dynamic linking to get this function.

    Please comment and correct me

  10. #10
    Join Date
    May 2015
    Posts
    213

    Re: wcout compile error

    Sorry my earlier post is confusing.

    Just to make it cleasr, i started this thread thinking I will use the dynamic linking, and i got the error. So I was trying other option. But it looks like static linking is not possible (ie what i think).
    So my option is to correct the dll linking errors

  11. #11
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,544

    Re: wcout compile error

    Quote Originally Posted by pdk5 View Post
    Sorry my earlier post is confusing.

    Just to make it cleasr, i started this thread thinking I will use the dynamic linking, and i got the error. So I was trying other option. But it looks like static linking is not possible (ie what i think).
    So my option is to correct the dll linking errors
    Well, then it is a good reason to post your actual code, actual error message/code, and explain a bit more clear your project settings.
    Victor Nijegorodov

  12. #12
    Join Date
    May 2015
    Posts
    213

    Re: wcout compile error

    Thanks a lot kaud and also Victor

    Finally I am able to invoke the function call from the dll .

    Im sorry I should have done home work of reading about this. But was coming from different platform was bit of mindblock

    Thanks a lot for your time and help.

    I will continue to debug further !

  13. #13
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,544

    Re: wcout compile error

    Glad you have solve your problem (at least partially).
    Good luck in your further debugging!
    Victor Nijegorodov

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)