PDA

Click to See Complete Forum and Search --> : i really need help!


Dec 20th, 2000, 04:18 PM
I have written some programs for editing Red Alert 2 in VB5. I needed some code and was given it by someone, but in VC++5. I really would appreciate help porting it as I have no idea what to do. If anyone can do this they will be highly honoured in future programs and all other things by me, especially on my website. The code is this:

#include "stdafx.h"
#include "cc_structures.h"
#include "shp_decode.h"
#include "shp_ts_file_write.h"

static void copy_image(const byte* s, byte* d, int s_x, int s_y, int s_cx, int d_cx, int d_cy)
{
const byte* r = s + s_x + s_cx * s_y;
byte* w = d;
while (d_cy--)
{
memcpy(w, r, d_cx);
r += s_cx;
w += d_cx;
}
}

int shp_ts_file_write(const byte* s, byte* d, int global_cx, int global_cy, int c_images)
{
const byte* r = s;
byte* w = d;
t_shp_ts_header& header = *reinterpret_cast<t_shp_ts_header*>(w);
header.zero = 0;
header.cx = global_cx;
header.cy = global_cy;
header.c_images = c_images;
w += sizeof(t_shp_ts_header);
byte* w1 = d + sizeof(t_shp_ts_header) + c_images * sizeof(t_shp_ts_image_header);
byte* t = new byte[global_cx * global_cy];
byte* u = new byte[(global_cx + 1) * global_cy * 2];
for (int i = 0; i < c_images; i++)
{
int x = 0;
int y = 0;
int cx = 0;
int cy = 0;
const byte* r0 = r;
const byte* r1 = r + global_cx * global_cy;
bool empty0, empty1;
empty0 = empty1 = true;
for (int yl = 0; yl < global_cy; yl++)
{
for (int xl = 0; xl < global_cx; xl++)
{
if (empty0 && *r0++)
{
empty0 = false;
y = yl;
}
if (empty1 && *--r1)
{
empty1 = false;
cy = global_cy - yl;
}
}
}
empty0 = empty1 = true;
for (int xl = 0; xl < global_cx; xl++)
{
for (int yl = y; yl < cy; yl++)
{
const byte* r0 = r + xl + global_cx * yl;
const byte* r1 = r + (global_cx - xl - 1) + global_cx * yl;
if (empty0 && *r0)
{
empty0 = false;
x = xl;
}
if (empty1 && *r1)
{
empty1 = false;
cx = global_cx - xl;
}
}
}
cx -= x;
cy -= y;
t_shp_ts_image_header& image_header = *reinterpret_cast<t_shp_ts_image_header*>(w);
image_header.x = x;
image_header.y = y;
image_header.cx = cx;
image_header.cy = cy;
image_header.compression = 0;
image_header.unknown = 0;
image_header.zero = 0;
image_header.offset = w1 - d;
w += sizeof(t_shp_ts_image_header);
if (cy)
{
copy_image(r, t, x, y, global_cx, cx, cy);
int cb_u = encode3(t, u, cx, cy);
if (cb_u < cx * cy)
{
image_header.compression = 3;
memcpy(w1, u, cb_u);
w1 += cb_u;
}
else
{
memcpy(w1, t, cx * cy);
w1 += cx * cy;
}
}
else
image_header.offset = 0;
r += global_cx * global_cy;
w1 = d + (w1 - d + 7 & ~7);
}
delete[] u;
delete[] t;
return w1 - d;
}

All I need is this code in a VB style, or if not a way of getting this into VB wihtout learning C++! Can this be used as a dll or something? Please help! :)

HarryW
Dec 20th, 2000, 04:29 PM
Make it into a dll. What function do you want to call from VB?

Dec 21st, 2000, 03:16 AM
What I am trying to do is convert a PCX file to a SHP file. How would I go about including this DLL in VB? This is the code, and I have Visual Studio 97 so i have everything, but how do i get it into VB?