Click here to Skip to main content
11,411,494 members (64,197 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VC6 Linux Console
I have a Win32 application (Visual C++ 6) that uses HINSTANCE to call an external DLL.
I need to convert it to a console app that take 1 argument and echo the result because I intend of using it on linux (compiling it using mono).
Here is a copy of the main.cpp:
#include "stdafx.h"
#include "testlib.c"

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{ 	
	LoadTestLibrary();
 
// etc....
}

in testlib.c I have:
HINSTANCE TESTLIB=NULL;
 
long LoadTestLibrary()
{
TESTLIB=LoadLibrary("TESTLIB.DLL");
if(TESTLIB == NULL)
 {
  MessageBox(NULL, "Unable to load TESTLIB.DLL", "ERROR", MB_OK);
  return(-1);
 }
else
 {
// process the data and echo the result
}
Is it possible to do it.
Thanks
Posted 12-Dec-12 8:36am
Edited 12-Dec-12 8:54am
RyanDev151.3K
v2
Comments
Sergey Alexandrovich Kryukov at 12-Dec-12 15:56pm
   
It would be quite possible if you asked correctly and explained the problem. There is no "conversion", you just need to write console code and re-use some of your existing code. But this is not CLI code but a Windows code. What should be executed under Mono?
--SA
Peterman3 at 12-Dec-12 16:46pm
   
I would like to write a CLI code like:
int main(int argc, char *argv[])
{
printf("Hello, world\n");
}
But I don't know how to rewrite this win32...
I get a compile error :
...recoicr.c(95): error C2146: syntax error : missing ';' before identifier 'TESTLIB'

I have not programmed in VC++ since 1995...
Peterman3 at 12-Dec-12 20:51pm
   
Here is the full source code in the main.cpp:

#include "stdafx.h"
#include "recoicr.c"

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
LoadICRLibrary();
int Session= ICR_Init("demo", "demo");
ICR_SelectRecognizer(Session, ".\\digit.rec");
long hBitmap;
char RecognizedString[255];
bool bAvail= IsClipboardFormatAvailable(CF_DIB);
hBitmap = 0;
if (bAvail)
{
::OpenClipboard(NULL);
hBitmap = (long) GetClipboardData(CF_DIB);
int nChar= ICR_RecognizeLine(Session, (long) hBitmap, 0);
::CloseClipboard();
if (nChar>0) {
nChar = ICR_GetResultValue(Session, RecognizedString);
RecognizedString[nChar]=0;
MessageBox(NULL, RecognizedString, "RESULT", MB_OK);
}
else MessageBox(NULL, "No data recognized !", "ERROR", MB_OK);
}
else
MessageBox(NULL, "Unable to paste DIB", "ERROR", MB_OK);
ICR_Done(Session);
FreeICRLibrary();
return 0;
}
Peterman3 at 12-Dec-12 20:54pm
   
Here is the full source code in the recoicr.c:

typedef long (__stdcall *ICR_INIT) (char*, char*);
ICR_INIT ICR_Init;

typedef void (__stdcall*ICR_DONE) (long);
ICR_DONE ICR_Done;

typedef void (__stdcall *ICR_SELECTRECOGNIZER) (long, char*);
ICR_SELECTRECOGNIZER ICR_SelectRecognizer;

typedef long (__stdcall *ICR_RECOGNIZECHAR) (long, long, long);
ICR_RECOGNIZECHAR ICR_RecognizeChar;

typedef long (__stdcall *ICR_RECOGNIZEWORD) (long, long, long);
ICR_RECOGNIZEWORD ICR_RecognizeWord;

typedef long (__stdcall *ICR_RECOGNIZELINE) (long, long, long);
ICR_RECOGNIZELINE ICR_RecognizeLine;

typedef long (__stdcall *ICR_RECOGNIZEPARAGRAPH) (long, long, long);
ICR_RECOGNIZEPARAGRAPH ICR_RecognizeParagraph;

typedef long (__stdcall *ICR_GETRESULTLEN) (long);
ICR_GETRESULTLEN ICR_GetResultLen;

typedef long (__stdcall *ICR_GETRESULTCONFIDENCE) (long);
ICR_GETRESULTCONFIDENCE ICR_GetResultConfidence;

typedef long (__stdcall *ICR_GETRESULTVALUE) (long, char*);
ICR_GETRESULTVALUE ICR_GetResultValue;

typedef void (__stdcall *ICR_GETCHARACTERVALUE) (long, long, long, char*);
ICR_GETCHARACTERVALUE ICR_GetCharacterValue;

typedef void (__stdcall *ICR_GETCHARACTERCONFIDENCE) (long, long, long, long*);
ICR_GETCHARACTERCONFIDENCE ICR_GetCharacterConfidence;

typedef void (__stdcall *ICR_GETCHARACTERRECT) (long, long, long*, long*, long*,long*);
ICR_GETCHARACTERRECT ICR_GetCharacterRect;

typedef long (__stdcall *ICR_GETCHARACTERSCOUNT) (long);
ICR_GETCHARACTERSCOUNT ICR_GetCharactersCount;


// ICR Library handle
HINSTANCE ICRLIB=NULL;

// Use this funciton to load dynamically the ICR library
// The function return -1 if the library is not found or 0 if all goes right

long LoadICRLibrary()
{
ICRLIB=LoadLibrary("RECOICR.DLL");
if(ICRLIB == NULL)
{
MessageBox(NULL, "Unable to load RECOICR.DLL", "ERROR", MB_OK);
return(-1);
}
else
{
ICR_Init=(ICR_INIT)GetProcAddress(ICRLIB,"ICR_Init");
ICR_Done=(ICR_DONE)GetProcAddress(ICRLIB,"ICR_Done");
ICR_SelectRecognizer=(ICR_SELECTRECOGNIZER)GetProcAddress(ICRLIB,"ICR_SelectRecognizer");
ICR_RecognizeChar=(ICR_RECOGNIZECHAR)GetProcAddress(ICRLIB,"ICR_RecognizeChar");
ICR_RecognizeWord=(ICR_RECOGNIZEWORD)GetProcAddress(ICRLIB,"ICR_RecognizeWord");
ICR_RecognizeLine=(ICR_RECOGNIZELINE)GetProcAddress(ICRLIB,"ICR_RecognizeLine");
ICR_RecognizeParagraph=(ICR_RECOGNIZEPARAGRAPH)GetProcAddress(ICRLIB,"ICR_RecognizeParagraph");
ICR_GetResultLen=(ICR_GETRESULTLEN)GetProcAddress(ICRLIB,"ICR_GetResultLen");
ICR_GetResultConfidence=(ICR_GETRESULTCONFIDENCE)GetProcAddress(ICRLIB,"ICR_GetResultConfidence");
ICR_GetResultValue=(ICR_GETRESULTVALUE)GetProcAddress(ICRLIB,"ICR_GetResultValue");
ICR_GetCharacterValue=(ICR_GETCHARACTERVALUE)GetProcAddress(ICRLIB,"ICR_GetCharacterValue");
ICR_GetCharacterConfidence=(ICR_GETCHARACTERCONFIDENCE)GetProcAddress(ICRLIB,"ICR_GetCharacterConfidence");
ICR_GetCharacterRect=(ICR_GETCHARACTERRECT)GetProcAddress(ICRLIB,"ICR_GetCharacterRect");
ICR_GetCharactersCount=(ICR_GETCHARACTERSCOUNT)GetProcAddress(ICRLIB,"ICR_GetCharactersCount");
return(0);
}
}


// Use this funciton to unload the ICR library when you don't need it

void FreeICRLibrary()
{
if (ICRLIB != NULL)
{
FreeLibrary(ICRLIB);
ICRLIB = NULL;
}
}
Peterman3 at 12-Dec-12 21:00pm
   
The current win32 app takes the data image from the clipboard, process it and return the result in a window. What I want is to a console app that takes the data image as the first argument (eg: test.exe XXXXX) and echo result.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You still need to include "windows.h" for the windows application even if it is a 'console' application because you want to use calls like LoadLibrary and such, which are perfectly valid to call.

You obviously need to remove the message boxes and other calls that bring up windows, if you don't want a 'window interface' at all on your program.

I think the oriignal error you mentioned was because it did not have a declaration for LoadLibrary function.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 223
1 Sergey Alexandrovich Kryukov 195
2 Sascha Lefévre 155
3 ProgramFOX 90
4 Dave Kreskowiak 90
0 Sergey Alexandrovich Kryukov 8,920
1 OriginalGriff 7,128
2 Maciej Los 3,440
3 Abhinav S 3,248
4 Peter Leow 3,059


Advertise | Privacy | Mobile
Web02 | 2.8.150414.5 | Last Updated 20 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100