Converting C++ API Calls

GrexD

Well-known member
Joined
Mar 5, 2008
Messages
95
Programming Experience
Beginner
It has been a while but I've done this before. I'm having trouble with this one because of the CHAR data type (e.g. DSSPDF_New). From what I can tell this would be byte in vb but I know that I need to pass strings. ByVal varname As String doesn't work - Bad DLL Calling Convention. As byte doesn't work either. If I declare a variable As Byte and try and pass it it crashes.

Any help is appreciated.

This is a link to some C code making the API calls. The DLL is free from dreamsyssoft. I've asked if they have VB API calls, but no response yet.

DreamSys Free PDF Library (Text and Image to PDF)

VB.NET:
#pragma once

#ifdef PDF_DLL_EXPORT
	#define PDFAPI _declspec(dllexport)
#else
	#define PDFAPI _declspec(dllimport)
#endif

#ifdef __cplusplus
extern "C" {
#endif

typedef unsigned char byte;

typedef int (*GetTiff)(void *, byte **, int *);
typedef void (*FreeTiff)(void *);

typedef void * PDF_HANDLE;
typedef void * SECTION_HANDLE;

#define TYPE_TIFF 0
#define TYPE_BMP 1

typedef struct _TIFF_DATA
{
	GetTiff getTiff;
	FreeTiff freeTiff;
	void *data;
	int type;
} TIFF_DATA;

PDFAPI PDF_HANDLE DSSPDF_New(char *title, char *producer);
PDFAPI SECTION_HANDLE DSSPDF_AddSection(PDF_HANDLE hPdf, char *sectionName);
PDFAPI void DSSPDF_AddPage(SECTION_HANDLE hSection, TIFF_DATA *page);
PDFAPI void DSSPDF_AddFilePage(SECTION_HANDLE hSection, char *fileName); //, int type);
PDFAPI void DSSPDF_Save(PDF_HANDLE hPdf, char *fileName);
PDFAPI void DSSPDF_Free(PDF_HANDLE hPdf);

#ifdef __cplusplus
}
#endif
 
I think thats because that is not actually a byte but instead a pointer to a byte or a pointer to a pointer to a byte because the two stars is confusing me a little. That is what it looks like to me at least. The only API calls I really make are to the Win32 API and it seems like most of them have been converted to regular .NET Libraries. All other references I just add the DLL as a reference to my project and if I cannot I usually make some sort of wrapper DLL in C++.NET and reference it like that. It is probably requesting some sort of 8,16,32,64 bit unsigned integer variable. But you may want to consider trying to work with this in C++ if you cannot figure it out and then referencing the C++.NET DLL.
 
But you may want to consider trying to work with this in C++ if you cannot figure it out and then referencing the C++.NET DLL.

Ugh! This is what I was hoping to avoid. I have not programmed in C in more than 10 years. Thanks for the feedback, though.
 
PDFAPI PDF_HANDLE DSSPDF_New(char *title, char *producer);

title here is, as you probably know, is a pointer to an ANSI string. I'm not sure how the framework will handle this probably using WideCharToMultiByte. However it should all be done for you. Passing a .Net string by reference should produce the desired result seeing as it's only a pointer a memory location where the string begins (or ends as the case may be).

You should also marshall the string explicitly as LPStr but then of course you won't need to pass ByRef.
 
I just sometimes feel that VB.NET was not meant to be used with certain API's. This is from my experience trying to get Win32 API calls to work in VB.NET. They say things are converted but they are not the same. Like Keys.SendKeys() or whatever does not work the same as SendMessage and all the special parameters. Just if I am working with an API that has a char* data type I just make a little wrapper class in C++ and reference it from my VB Project. It gives me that warm, safe, fuzzy feeling. :eek:
 
VB.Net has the capability of calling any and all API's as has c#. If it couldn't the framework wouldn't work at all seeing as just about everything you do in .Net will eventually filter down to some kind of interop.
 
Ok, well, I guess I'll look in to a C wrapper for this. It has been so long since I've done anything in C, who knows how long it will take.

What I need to be able to to is convert Tif files (incoming faxes) to PDFs. I need to be able to do this in code, on the fly. The program is waiting for incoming faxes. When one arrives the program (user) views the tif image - this is done - and then the user will route it to another location. As it is routed it needs to be converted to a PDF.

Any ideas?
 
I'm not sure if I tried exactly what you stated. I tried everything I could think of and couldn't get it to work. I'm still kind of new to vb.net, so the whole "marshalling" idea is a bit foreign to me. I think the MultiByteToWideChar() might do it, but I ended up abandoning the dll calls in favor the Adobe SDK. I don't know why I didn't think of that first. It came with a lot of .net samples.

Thanks for the input...
 
Back
Top