Looks like a very simple problem:
VS2017 15.9.13 (The latest version today)
My main program, followed by a DLL:
#include <windows.h>
#include <stdio.h>
#include <time.h>
extern "C" int WINAPI wWinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow )
{
time_t now = time ( 0 );
FILE *log = _wfopen ( L"test.dat", L"wt,ccs = UNICODE" );
if ( HMODULE hdll = LoadLibrary ( L"Dll1" ) )
{
typedef int ( _cdecl *typeCreate )(int, FILE *);
typeCreate Create = ( typeCreate ) GetProcAddress ( hdll, "MySub" );
if ( Create )
{
fwprintf ( log, L"Test 2 at %s", _wctime ( &now ) ); fflush ( log );
int nn = ftell ( log );
int n = 21;
nn = Create ( n, log );
}
}
fclose (f);
return EXIT_SUCCESS;
}
#include <stdio.h>
extern "C" __declspec (dllexport) int MySub ( int n, FILE *f )
{
int nn = 0;
if ( f )
{
nn = ftell ( f );
fwprintf ( f, L"Number %d\n", n );
fflush ( f );
nn = ftell ( f );
}
return nn;
}
Running this program, after changing and resetting some project settings fails with:
Debug assertion failed!
Program: C:\xxxxxx\Dll1\Debug\Project1.exe
File: minkernel\crts\ucrt\src\appcrt\lowio\lseek.cpp
Line: 103
Expression: _osfile(fh) & FOPEN
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.
(Press Retry to debug the application)
What I have tried:
When this project is freshly created it works as expected. After making (and reverting) some project settings, like specifying Windows 8.1 as the Windows SDK version, the program keeps failing on the ftell statement in the DLL, no matter what I try.
I have the complete project available as a zip file, but I don't see a way to upload this file.
Hoping for a good suggestion,
Henk B