How to get window main handle?

My code is as follows:


#include <Mstn\MdlApi\MdlApi.h>
#include <Mstn\cmdlist.r.h>
#include <Mstn\MdlApi\msnativewindow.h>
#include <windows.h>
#include <DgnPlatform\DgnFile.h>
#include <DgnPlatform\DgnFileIO\DgnFileIOApi.h>

extern "C" DLLEXPORT void MdlMain(int argc, WCharCP argv[])
{
             HWND hWnd = NULL;
             hWnd = (HWND)mdlNativeWindow_getMainHandle(0);


            return;

}

I can't able to resolve these build errors.

Parents Reply Children
  • And? Did you solve it? Did your learn what this error means? It's standard (and often received) C++ linker information.

    What MicroStation libraries do you link?

    Hi Jan,

    No, I am still facing this issue. 

    #---------------------------------------------------------------------------------------+
    #
    #    $Source: hc_microstation.mke $
    # 
    #    $Copyright: (c) 2017 Bentley Systems, Incorporated. All rights reserved. $
    #
    #---------------------------------------------------------------------------------------+
    PolicyFile = MicroStationPolicy.mki
    
    appName     =  hc_microstation
    sAppName    =  hc_microstation
    
    MDLMKI = $(MSMDE)mki/
    mdlLibs = $(MSMDE)library/
    hc_out = D:/Repository/microstation_main/bin/x64/Release/
    
    dirToSearch = $(MDLMKI)
    
    genSrc = $(o)
    
    %include $(MDLMKI)mdl.mki 
    
    #--------------------------------------------------------------------------------------
    #    Create needed output directories in case they don't exist
    #--------------------------------------------------------------------------------------
    always:
        !~@mkdir $(o)
        !~@mkdir $(rscObjects)
        !~@mkdir $(reqdObjs)
    
    dirToSearch = $(o)
    %include cincapnd.mki
    
    #--------------------------------------------------------------------------------------
    #    Define macros specific to this example
    #--------------------------------------------------------------------------------------
    privateInc      = $(baseDir)
    langSpec        = $(baseDir)transkit/
    
    libRscs = \
        $(rscObjects)$(sAppName).rsc
    
    #--------------------------------------------------------------------------------------
    #    Create object files
    #--------------------------------------------------------------------------------------
    $(rscObjects)$(sAppName).rsc     : $(baseDir)$(sAppName).r
    
    $(o)$(sAppName).h                : $(baseDir)$(sAppName).r
    
    #--------------------------------------------------------------------------------------
    #    Set up to use dlmcomp.mki and dlmlink.mki
    #--------------------------------------------------------------------------------------
    
    DLM_NAME                = $(appName)
    DLM_DEST                = $(mdlapps)
    DLM_OBJECT_FILES        = $(o)$(appName)$(oext)
    DLM_OBJECT_DEST         = $(o)
    DLM_LIBDEF_SRC          = $(_MakeFilePath)
    DLM_SPECIAL_LINKOPT     = -fixed:no     # Notify linker this library does not require a fixed base address to load
    DLM_NO_DLS              = 1             # USE DLLEXPORT IN .CPP
    DLM_NO_DEF              = 1
    DLM_NOENTRY             = 1
    DLM_NO_MANIFEST         = 1             # If not set linker embeds your current (developer) patched MSVCRT version manifest in output dll.  This is not desirable and produces side-by-side CLIENT ERROR: 14001)
    DLM_NO_SIGN             = 1             # If not set and no certificate found, ERROR: 'singleton' is not recognized as an internal or external command
    DLM_NO_INITIALIZE_FUNCTION  = 1
    
    LINKER_LIBRARIES + $(mdlLibs)bentley.lib
    LINKER_LIBRARIES + $(mdlLibs)mdlbltin.lib
    LINKER_LIBRARIES + $(mdlLibs)BentleyGeom.lib
    LINKER_LIBRARIES + $(mdlLibs)DgnPlatform.lib
    LINKER_LIBRARIES + $(mdlLibs)dgnview.lib
    LINKER_LIBRARIES + $(mdlLibs)RmgrTools.lib
    LINKER_LIBRARIES + $(mdlLibs)BentleyAllocator.lib
    LINKER_LIBRARIES + $(hc_out)hc.shield.lib
    LINKER_LIBRARIES + $(hc_out)hc.ui.lib
    
    
    #--------------------------------------------------------------------------------------
    #    Compile the source files for the DLM
    #--------------------------------------------------------------------------------------
    $(o)$(appName)$(oext)       : $(baseDir)$(appName).cpp
    
    %include $(MDLMKI)dlmlink.mki
    
    #--------------------------------------------------------------------------------------
    #    Merge the dialog resources & MDL program file using rlib
    #--------------------------------------------------------------------------------------
    $(reqdObjs)$(appName).mi        : $(libRscs)
        $(msg)
        > $(o)make.opt
        -o$@
        $(libRscs)
        <
        $(RLibCmd) @$(o)make.opt
        ~time
    
    #--------------------------------------------------------------------------------------
    #    complete construction of the .ma
    #--------------------------------------------------------------------------------------
    libRscs = \
        $(reqdObjs)$(appName).mi
    
    $(mdlapps)$(appName).ma : $(libRscs)
            $(msg)
            > $(rscObjects)make.opt
            -o$@
            $(libRscs)
            <
            $(RLibCmd) @$(rscObjects)make.opt
            ~time

    I have gone through many forums but still i am stuck.

    Is there anything library need to include??

    Regards,

    Rajesh

  • Hi Rajesh,

    No, I am still facing this issue. 

    it's because you do not follow my and Bob's advises.

    • Me (general advice): What MicroStation libraries do you link?
    • Bob (specific advice): Bmake Compile errors.  Do you have nativewindow.lib in your LINKER_LIBRARIES list in your project mke file?
    Is there anything library need to include??

    It's C++ rule that for every function or class used, you have to ensure proper library will be linked. So when you use mdlNativeWindow_getMainHandle(), you have to link the proper library. And Bob already told you it's nativewindow.lib, but I do not see this library in your makefile.

    You do not share output from bmake process (not what Visual Studio shows you, but what bmake reports when started manually). Maybe you even do not try to understand what compiler and linker tell you? I can guess only, but I assume the linker complains in this way (output for another project and another missing lib):

    ElementsExampleQueryTool.obj : error LNK2001: unresolved external symbol 
    "protected: virtual void __cdecl Bentley::DgnPlatform::DgnElementSetTool::_ModifyAgendaEntries(void)"
    (?_ModifyAgendaEntries@DgnElementSetTool@DgnPlatform@Bentley@@MEAAXXZ)

    which tells exactly error id (so can be searched in this forum and on Internet) and also what class or method cannot be linked (so documentation can be consulted, or when the information is not found, tools like dllexp or dumpbin can be used to find the right library).

    but still i am stuck.

    I think the main problem that is that without proper C++ development skills (and C++ is known as not only complicated language, but also language with very complex requirement for build process) you try to start with MicroStation app development (which adds extra levels of complexity on top of C++), where to know all details how C++ works is mandatory.

    It's like to learn how to drive car after injury and surgery, without finished convalescence and physiotherapy, trying to learn traffic rules and legal context during driving, not before. Ignoring the process "one step after another" never leads do good and efficient results.

    My code is as follows:

    Now I have noticed ... did you think about your code?

    I have no idea what will happen, I do not think you will receive any valid handle before you switch MicroStation to graphics mode. Is there any "main windows" when MicroStation is not in graphics mode?

    Regards,

      Jan