Passing info out of a DLL

Posted on 2002-06-16
Last Modified: 2010-04-01
I know next to nothing about Windows API, DirectX and vc++, but I want to pass System/DirectX information back to another language.
Anything passed to out or returned I can capture from Blitz Basic, but how do I pass it?
I have made working dll's along the lines of the following:

from test.cpp

int testint( int const *in,int in_size,int *out,int out_sz )
     int ddcheck = 1;
     *(int*)out = ddcheck;


int testfloats( int const *in,int in_size,int *out,int out_sz )
     float i = 1.234567;
    *(float*)out = i;

int teststring( int const *in,int in_size,int *out,int out_sz )
     char name[100] = "Just some text adsfhashd asflash dfkjhsadf jhaslkjfh s";


int iotest( int const *in,int in_size,int *out,int out_sz )
     int i = *(int*)in;
    *(int*)out = i;

my header file contains this type of code for each function:
extern "C"{
_declspec(dllexport) int _cdecl teststring( int const *in,int in_size,int *out,int out_sz );

Anything passed to out or returned I can capture from Blitz Basic, but how do I pass it?
For example I want to pass back the DeviceEnumeration information that is held in a struct, I also need to be able to pass back the hwnd, and more...
1) How to pass back struct information
2) How to pass back hwnd information.
3) How to pass back other non-char,non-int, non-float information.
Working source of passing DirectX info back would be a bonus!
All help greatly appreciated
Question by:cyderpunk
LVL 23

Accepted Solution

Roshan Davis earned 500 total points
ID: 7082916
You call this below function with null pointer, then the function should return the size though the parameter pnSize, after that, u have to allocate that much size, then the function should return the value by that pointer. This is the normal routine for data passing.

func(BYTE* ptrByte, int *pnSize)
     if ( ptrByte )
          *pnSize = m_nLength;
          memcpy(ptrByte, m_ptrBuffer, *pnSize);

Another thing is that, you can make the structure or array into a buffer. So the calling function again it make the buffer to the structure or array.


LVL 49

Expert Comment

ID: 7083056
hi cyberpunk,
I can't parse this sentence:
>>Anything passed to out or returned I can capture from Blitz Basic, but how do I pass it?

Is it your desire to call Windows API functions from Blitz Basic (what is Blitz Basic?).  Or do you want Blitz Basic to call a C++ DLL so that *it* can call Windows API? (if so, why?)  Or do you want to write a C++ DLL to do something having to do with DirectX?  Or what?  Please advise.  Thanks!

-- Dan

Author Comment

ID: 7083424
I can create working dlls to pass some infoormation, ie floats, ints, chars, as in my source above, but i cant get structs out.
The purpose of the dll is to provide information (Directx/System) that has no equivalent command in Blitz.
Basically I dont understand the data type and how to pass them back.
>>Anything passed to out or returned I can capture from Blitz Basic, but how do I pass it?
What I  meant by that was any value returned by the function i can capture and use, and any value passed to the out( declared above) i can capture but how to i persuade vc++ to pass these (ie hwnd & DDEnum) data types to a function that must conform to the above format.
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

LVL 49

Expert Comment

ID: 7084663
You need to do about what roshman suggested.  

Many paramters (such as HWND, or HANDLE) are 32-bit values -- unsigned ints.  That should be no problem.   In the case of a string, you will need to know how Bliz Basic works.  It can be quite tricky *returning* string data to Ms Visual Basic from a DLL, so you may encounter similar problems.  In general, pass in a buffer and let C++ fill it in with a null-terminated string and then figure out how BlitzBasic will handle that situation.

For a data structure such as a BITMAPINFO record, the Basic program should provide a buffer of adequate size.  The C++ program will fill that buffer.  Then the Basic program will need to be able to access the individual members of that structure.  Does Blitz Basic support a concept like "custom data types?"  If so, you can layout a custom record so that you can access the parts of the data strucure.

-- Dan
LVL 11

Expert Comment

ID: 7262356
Dear cyderpunk

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to accept


comment(s) as an answer.


Expert Comment

ID: 7332950
Force accepted

** Mindphaser - Community Support Moderator **

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question