• Welcome to Jose's Read Only Forum 2023.
 

TCLib update for Patrice

Started by James C. Fuller, March 08, 2017, 12:04:58 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

James C. Fuller

Patrice,
  I added sin,cos,acos,asin,atan,atan2,sqrt,time,rand,srand,fmod,fmodf to TCLib.
If there are other ones you need for testing let me know.
I am going to add most all the math functions but I want to install the new Visual Studio 2017 community today.

James

Patrice Terrier

James

That doesn't work by me, from inside the IDE, no DllMain external symbol.
and a bunch of unresolved external

Did you try to compile the DLL project that was in my zip?

Thanks anyway ;)


Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

James C. Fuller

Patrice,
  You have to be careful with your #includes and not #include files that in turn #include the standard <c lib headers>.
This appears to be the case with mfapi.h amd shlwapi.h
Probably just not worth the effort with the type of apps/dlls you write.

James

James C. Fuller

Patrice,
  There are no issues with the GL.h and GLU.h.
Maybe if you prototyped just the calls from mfapi.h and shlwapi.h you use I could figure it out.
I am close I think ?? :)

James

 

Patrice Terrier

#4
i shall make another try later this day, after adding the missing DllMain entry point.

thanks
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

James C. Fuller

Patrice,
  Try to make another standard Visual studio project like the one you posted without including  mfapi.h and shlwapi.h, instead add the prototypes of the functions used in the source. I forgot to add tan (DUH) to TCLib so that will fail until I update and post a new TCLib.
Also there are a couple of calls in IsFileImage that are not supported (yet):
_wsplitpath_s
wcsncat_s
wcsstr

James



Patrice Terrier

rand, and srand are causing me havoc
--> redefinition, previous definition was 'function'.
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

James C. Fuller

Patrice,
  Yeah that is one of the issues you have to be aware of. One of your includes is also including the sdk <stdlib.h>
It's going to take a bit more planning on your part on managing #include files and prototypes.
What I would suggest if/when you decide to continue is to create tour own versions of includes you need and put them in the TCLib folder.
I have a mixed version (bc9/c++) of your dll compiled but don't quite know what to do with it to test?
It comes in at 12k.

James


Patrice Terrier

#8
I don't know how to resolve these 3 link errors (see the attached screen shot)

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

James C. Fuller

Patrice,
  I updated the library and it should help.
Attached is the new library and includes along with my version of your dll.
To compile: TBLIBDLL.BAT LB01

James

James C. Fuller

I just noticed I hadn't finished up work in IsFileImage so it will not work as is.

James

Patrice Terrier

I could remove the IsFileImage function, because in that specific case, a texture should be always a valid image file name.

I have written my own replacement for PathCombine, based on direct use of the RtlMoveMemory

void Path_Combine(OUT WCHAR* zResource, IN WCHAR* path, IN WCHAR* combine) {
    long offset = (long) wcslen(path) * sizeof(WCHAR);
    ZeroMemory(zResource, MAX_PATH);
    MoveMemory(zResource, path, offset);
    MoveMemory(&zResource[offset / 2], &combine[0], (long) wcslen(combine) * sizeof(WCHAR));
}



Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

James C. Fuller

Patrice,
  It's just the header files that are giving the problems.

Make your own for shlwapi.h in case you need something in the future and use #pragma comment(lib,"shlwapi.lib")

EXTERN_C LPWSTR  PathCombineA(_Out_writes_(MAX_PATH) LPWSTR pszDest, _In_opt_ LPCTSTR pszDir, _In_opt_ LPCTSTR pszFile);
EXTERN_C LPWSTR  PathCombineW(_Out_writes_(MAX_PATH) LPWSTR pszDest, _In_opt_ LPCWSTR pszDir, _In_opt_ LPCWSTR pszFile);
#ifdef UNICODE
#define PathCombine  PathCombineW
#else
#define PathCombine  PathCombineA
#endif
#define _MAX_DRIVE 3
#define _MAX_DIR 256
#define _MAX_FNAME 256
#define _MAX_EXT 256

James




Patrice Terrier

James--

From 108 Kb down to 13 Kb, that's amazing!!!

However in Math.h,  i still couldn't use
extern int (__cdecl* rand)(void);
extern void (__cdecl* srand)(unsigned int);

because of error C2365:  previous definition was function

Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Frederick J. Harris

#14
Does this help...


#ifdef TCLib
   int rand(void)
   {
    static unsigned int next = 1;
    next = next * 1103515245 + 12345;
    return (unsigned int)(next>>16) & RAND_MAX;
   }
#endif


size_t Rnd(int iMin, int iMax)
{
double dblRange=iMax-iMin;
double dblMaxFactor=dblRange/RAND_MAX;
double dblRandomNumber=(double)rand();

return iMin+dblMaxFactor*dblRandomNumber;
}


I was working with that some time ago.  I forget the details, and I forget where RAND_MAX is defined.  Possibly in stdlib.h.  My Rnd() function above is a quick and dirty interpretation of PowerBASIC's Rnd(), where one can specify a min and max value.  It just scales stuff about using stdlib's rand.  It worked OK for the use I made of it.  Random number generation can get to be a tricky subject if you let it!