Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 547
  • Last Modified:

Help with C DLL pass string


 Hi experts!

I’m totally new to MS VC 2008, but now I need to learn it on some level. I need a help with a call to external DLL function of Stradis decoder. My C project is OCX which call these functions. I have a working example from Stradis, however I’m not able to write my application ¿

Here you my code. Problem is with pass string – path and name of file. I get back error – File not found. File is existing in this part, so problem is with string pass.

For more sure I set value of sInitFile to be sure that problem is not due to conservation error when I pass this string to OCX from VB6.

// --------- My code with c OCX -----------------------
long CCPlayCtrl::Init(long lCard, long lVideoMode, LPCTSTR sInitFile)
{
      // TODO: Add your dispatch handler code here
      hDecoder = INVALID_STRADIS_HANDLE;
      STRADISDECODERSETTINGS phSettings;

      hDecoder = StradisDecoder_Create(lCard);
    StradisDecoder_DisplayErrorMessages( hDecoder, true);

      phSettings = StradisDecoderSettings_Create(VideoStandard_Auto/*(VideoStandard)lVideoMode*/);

  sInitFile="C:\\Saigon.mpg";

      int iRes = StradisDecoder_File_Open(hDecoder, sInitFile, phSettings); // RETURN ERROR _ FILE NOT FOUND

Bellow in the code section is a working example from SDK. This working example is compiled in VS C 2008 althod they are written in C6,it works and should be use like example what input string format demands this function. By the way, it was compiled under Unicode Solution Configuration, my example say stradis.dll can't be read while I try to compilie it under Debug Unicode and I compile it under Debug. Does this make error ???

For working code example ist with files which are opens are gets from Command String while start .exe.

Also in OCX this srting will be set from VB6. What type is more comfitable with VB6 ?



Declaration of function from MANUAL
------------------------------------
File_Open()
bool File_Open(char* pFileName, CStradisDecoderSettings* pSettings);

This function opens the requested disk file pointed to by pFileName and modifies the contents of the CStradisDecoderSettings pointed to by pSettings. If successfully opened, the file is bound to the pSettings class. 

This is from C code
-------------------
STRADIS_EXPORT int STRADISCALLMETHOD StradisDecoder_File_Open(STRADISDECODER hDecoder, LPCTSTR pFilename, STRADISDECODERSETTINGS hSettings);


Working code example. SHOULD BE USE TO SEE EXAMPLE OF WORKING STRING WHICH SHOULD BE PASS TO DLL
------------------------------------------------------------------------------------------------
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
	STRADISDECODER hDecoder = INVALID_STRADIS_HANDLE;
	STRADISDECODERSETTINGS* phSettings = NULL;
	int i = 0;                   // Shared index variable.
	int nExpectedFiles = argc-1; // Number of filenames expected on the command line (based on argc).
	int nFiles = 0;              // Number of files actually opened.
	int nDecoderIndex = 0;       // Index of the decoder to use.

#ifdef USE_MFC
	// MFC is not necessary for this application to run.
	// Initialize MFC and print and error on failure
	if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) {
		// TODO: change error code to suit your needs
		printf("Fatal Error: MFC initialization failed\n");
		return 1;
	}
#endif

	// Check for the correct number of arguments (at least one file).
	if(argc < 2) {
		printf("FilePlayC file1 <file2> <file3> ...\n");
		
		goto Exit;
	}

	// Create the decoder class for board 0 (first board)
	hDecoder = StradisDecoder_Create(nDecoderIndex);
	if(hDecoder == INVALID_STRADIS_HANDLE) {
		printf("Could not create decoder!\n");
		goto Exit;
	}
	if(StradisDecoder_IsValid(hDecoder) == false) {
		printf("Decoder invalid!\n");
		goto Exit;
	}
 
//	printf( hDecoder + "\n");

	// Initialize the Settings array and create a Settings handle for each file:
	phSettings = (STRADISDECODERSETTINGS*)malloc(sizeof(STRADISDECODERSETTINGS)*nExpectedFiles);
	memset(phSettings, 0x0, sizeof(STRADISDECODERSETTINGS)*nExpectedFiles);
	for(i = 0; i < nExpectedFiles; i++) {
		phSettings[i] = StradisDecoderSettings_Create(VideoStandard_Auto);
		if (phSettings[i] == INVALID_STRADIS_HANDLE) {
			printf("Could not create settings");
			goto Exit;
		}
	}

	// Open all of the files on the command line.
	for(i = 0; i < nExpectedFiles; i++) {
// -------------- HERE IS EXAMPLE ------------------
		TCHAR* szFilename = argv[i+1];
		if (StradisDecoder_File_Open(hDecoder, szFilename, phSettings[nFiles])) {
			_tprintf(_T("Could not open file %s: %s\n"), szFilename, Stradis_GetLastErrorText());
			continue;
		} else {
			nFiles++;
		}
	}

Open in new window

0
dvplayltd
Asked:
dvplayltd
3 Solutions
 
Xper4netCommented:
First, your string must be initialized as this :

  sInitFile=_T("C:\\Saigon.mpg") ;

If it doesn't work better, we could try to go further....
0
 
dvplayltdAuthor Commented:
To xPer4Net

I try this, result is same:
File not found

    sInitFile=_T("C:\\Saigon.mpg") ;

      int iRes = StradisDecoder_File_Open(hDecoder, sInitFile/*szFilename*/, phSettings);

What other to try ?
0
 
masheikCommented:
can you try

strcpy(sInitFile,"C:\\Saigon.mpg");

or

sInitFile = strdup("C:\\Saigon.mpg");

.....code ....

free(sInitFile);

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
dvplayltdAuthor Commented:
I try

strcpy(sInitFile,"C:\\Saigon.mpg");

and get:
Error      1      error C2664: 'strcpy' : cannot convert parameter 1 from 'LPCTSTR' to 'char *'      d:\aadinserter\stardisocx\cplay\cplayctl.cpp      264      CPlay

Problem is not to set value, problem is with format of string. I think it demand Char pointer to first simbol which should be pass in array of chars ? Look def. of function:
bool File_Open(char* pFileName, CStradisDecoderSettings* pSettings);

Also, it should be unicode, does this make diffrances ?
0
 
dvplayltdAuthor Commented:
I mean, look this from example which works fine:

TCHAR* argv[]

      for(i = 0; i < nExpectedFiles; i++) {
            TCHAR* szFilename = argv[i+1];
            if (StradisDecoder_File_Open(hDecoder, szFilename, phSettings[nFiles])) {
                  _tprintf(_T("Could not open file %s: %s\n"), szFilename, Stradis_GetLastErrorText());
                  continue;
            } else {
                  nFiles++;
            }
      }

So my value should go to type TCHAR* argv[]
 May be I needo some loop from my string to goes to this char array ? Please offer example code.
0
 
ZoppoCommented:
> So my value should go to type TCHAR* argv[]
> May be I needo some loop from my string to goes to this char array ? Please offer example code.

I think this is not correct - the loop you see in the sample code of your last comment IMO is used to open a number of files (passed via command line) one after another - each call to 'StradisDecoder_File_Open' gets passed a 'TCHAR*' as filename.

You should check if 'Stradis decoder's documentation has any information whether the filename has to be Unicode or not.

Further I would suggest to test it with another file path - the C:\ directory often has different permissions than other paths. Please try to create a path 'C:\temp', copy the 'saigon.mpg' to there and use 'C:\\temp\\saigon.mpg' in your code. Thus you can ensure it's not a permission problem ...

Further I think you should check the value returned by 'StradisDecoderSettings_Create' as it's done in the sample with:
if (phSettings[i] == INVALID_STRADIS_HANDLE)

Open in new window


ZOPPO
0
 
Xper4netCommented:
You said: "my example say stradis.dll can't be read while I try to compilie it under Debug Unicode"

I never encountered "dll can't be read" error message. Is it exactly that?

In the meantime, you can try the following :

TCHAR* pszFileName = __tcsdup(T_("C:\\Saigon.mpg")) ;

int iRes = StradisDecoder_File_Open(hDecoder, pszFileName , phSettings);
free(pszFileName) ;
0
 
dvplayltdAuthor Commented:
10x to all! I solve question when I change Charter Set to Unicode (Project settings), then I pass directly value without any transofm.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now