- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
#ifdef __cplusplus extern "C" { #endif BOOL WINAPI GetId(LPTSTR lpOutBuffer, int Mode); #ifdef __cplusplus } #endif ... char Id[50]; memset(Id, '', 50); BOOL result = GetId(Id, 0); if(result) { CString IdStr; IdStr = Id; MessageBox(IdStr); }
Code:CHARACTER*50 Id LOGICAL reslt INTERFACE LOGICAL FUNCTION GetId (Id,nin) !DEC$ ATTRIBUTES DLLIMPORT :: GetId CHARACTER Id*50 INTEGER nin END FUNCTION GetId END INTERFACE ... reslt = GetId(Id,0)
ifort myprogram.f90 mydll.lib
-out:myprogram.exe -subsystem:console -entry:mainCRTStartup myprogram.obj mydll.lib myprogram.obj : error LNK2019: unresolved external symbol __imp__GETID referenced in function _MAIN__ myprogram.exe : fatal error LNK1120: 1 unresolved externals
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
INTERFACE
LOGICAL FUNCTION GetId (Id,nin)
!DEC$ ATTRIBUTES C,DLLIMPORT,ALIAS:"GetID" :: GetId
CHARACTER Id*50
!DEC$ ATTRIBUTES REFERENCE :: Id
INTEGER nin
END FUNCTION GetId
END INTERFACE
Oh, and change that LOGICAL to INTEGER. Fortran LOGICAL is not the same as C BOOL.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
INTERFACE INTEGER FUNCTION GetId (Id,nin) !DEC$ ATTRIBUTES C,DLLIMPORT,ALIAS:"GetID" :: GetId CHARACTER Id*50 !DEC$ ATTRIBUTES REFERENCE :: Id INTEGER nin END FUNCTION GetId END INTERFACE
error LNK2019: unresolved external symbol __imp_GetId referenced in function _MAIN__
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Set default (cd) to the folder containing mydll.lib and type:
dumpbin -exports mydll.lib
Post the results.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
dumpbin -exports mydll.lib
Microsoft COFF/PE Dumper Version 7.10.3077 Copyright (C) Microsoft Corporation. All rights reserved. Dump of file mydll.lib File Type: LIBRARY
Exports
ordinal name
18 _FunctionOne@12 17 _FunctionTwo@12 4 _FunctionThree@16 ... ... 1 _GetId@8 ... ...
Summary
BA .debug$S 14 .idata$2 14 .idata$3 4 .idata$4 4 .idata$5 8 .idata$6
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So replace
!DEC$ ATTRIBUTES C,DLLIMPORT,ALIAS:"GetID" :: GetId
by
!DEC$ ATTRIBUTES STDCALL,DLLIMPORT,ALIAS:"GetID" :: GetId
and it will work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
!DEC$ATTRIBUTES DLLIMPORT, DECORATE, STDCALL, ALIAS: "GetId":: GetId
or
!DEC$ATTRIBUTES DLLIMPORT, STDCALL, ALIAS: "_GetId@8":: GetId
Jugoslav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
i'm trying to follow this example and am getting an error, i simply put in dll, on command when i type dumbpin -export mydll.dll promp it comes up ERSET_WRAPPER, then in the main project i copy over the dll and gives me the error _imp_ERSET_WRAPPER, do you need to have the name of the dll library somewhere like how C uses ("mydll.dll"), also tried putting in a module instead of a subroutine and i get a different error, if i take out call ERSET_WRAP(1,2,3) it compiles.
I just noticed i didnt do this thing with a .def, i tried link /dll mydll.dll mydef.def, but it says there isnt a mydef.def, is this thing necessary,thanks Jeremy
subroutine ERSET_WRAPPER(x,y,z)
!DEC$ ATTRIBUTES DLLEXPORT, ALIAS: "ERSET_WRAPPER" :: ERSET_WRAPPER
implicit none
integer
, intent(in) :: x,y,z end subroutinesubroutine
CALLERSET implicit none INTERFACE subroutine ERSET_WRAP(x,y,z) !DEC$ ATTRIBUTES DLLIMPORT, ALIAS: "ERSET_WRAPPER" :: ERSET_WRAP integer x,y,z !DEC$ ATTRIBUTES REFERENCE :: x,y,z end subroutine END INTERFACE call ERSET_WRAP(1,2,3)end subroutine
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
im confused on how to link the export library, do i put into the directory of executible or the path of the library directory through the properties of theexecutible, also why does the .lib get deleted from executible directory when it is rebuilt if it is put there, thanks Jeremy
OK, i got it. You put the dll in the directory of the executible and in the properties you tell it to look for the .lib
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I guess I still have two questions:
1. Why does the .lib file get deleted and the .dll doesnt,when placed in the executible directory, whenthe executible is rebuilt.
2. If I keep the .dll and .lib in the original directory of the library, i can tell it to find the lib in the command file of the linker by mylib.lib, but when i run it says the dll file was not found. Under additional library directories, I placed the link to where the lib and dll files are placed. Also, I went to project dependencies and placed: "Main depends on Library" and it doesnt seem to link. I had to place the dll in the exe. directory manually.
Thanks for your help, Jeremy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You do have to copy the DLL - best place is into the project directory (with the .vfproj file) of the executable project. I do this in a "Post-build step" rule in the DLL project.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page