Solved

Passing info out of a DLL

Posted on 2002-06-16
6
252 Views
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;
     return(0);

}

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

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

     strcpy((char*)out,name);
     
     return(0);
     
}

int iotest( int const *in,int in_size,int *out,int out_sz )
{
     int i = *(int*)in;
     i=i*33;
    *(int*)out = i;
    return(0);
}

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...
Questions:
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
0
Comment
Question by:cyderpunk
6 Comments
 
LVL 23

Accepted Solution

by:
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;
     else
          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.

Roshmon

0
 
LVL 49

Expert Comment

by:DanRollins
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
0
 

Author Comment

by:cyderpunk
ID: 7083424
DanRollins,
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.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 49

Expert Comment

by:DanRollins
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
0
 
LVL 11

Expert Comment

by:griessh
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

     "roshmon"

comment(s) as an answer.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 6

Expert Comment

by:Mindphaser
ID: 7332950
Force accepted

** Mindphaser - Community Support Moderator **
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

747 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now