I'm currently trying to use OpenSC on Windows from (ActiveState) Perl. I need to use a bunch of functions, but whatever i try i just can't get a working module

a read a number of tutorials, but i'm none the wiser. Here's the basics. I have two files, namely ccreadlib.h

#ifndef CCREADLIB_H #define CCREADLIB_H int CardConnect (void); char* CardGetName(void); int CardDisconnect(void); #endif

and ccreadlib.c:
#include <stdio.h> #include <stdlib.h> #ifdef HAVE_UNISTD_H #include <unistd.h> #endif #include <string.h> #include <errno.h> #include <ctype.h> #include <sys/stat.h> #include "libopensc/opensc.h" #include "libopensc/cardctl.h" #include "util.h" /* type for associations of IDs to names */ typedef struct _id2str { unsigned int id; const char *str; } id2str_t; static const char *app_name = "opensc-tool"; static int opt_wait = 0; static char ** opt_apdus; static char *opt_reader; static int opt_apdu_count = 0; static int verbose = 0; enum { OPT_SERIAL = 0x100, OPT_LIST_ALG }; static sc_context_t *ctx = NULL; static sc_card_t *card = NULL; int CardConnect (void) { int err = 0, r, c, long_optind = 0; const char *opt_driver = NULL; const char *opt_conf_entry = NULL; sc_context_param_t ctx_param; setbuf(stderr, NULL); setbuf(stdout, NULL); memset(&ctx_param, 0, sizeof(ctx_param)); ctx_param.ver = 0; ctx_param.app_name = app_name; r = sc_context_create(&ctx, &ctx_param); if (r) { //fprintf(stderr, "Failed to establish context: %s\n", sc_stre +rror(r)); return 1; } err = util_connect_card(ctx, &card, opt_reader, opt_wait, verbose) +; if (err) { CardDisconnect(); return 2; } return 0; } char* CardGetName(void) { printf("Card name: "); printf("%s\n", card->name); return card->name; } int CardDisconnect(void) { if (card) { sc_unlock(card); sc_disconnect_card(card); card = NULL; } if (ctx) { sc_release_context(ctx); ctx = NULL; } return 0; }

There are also a number of supporting files: utils.c/h, header files in the folder libopensc and the library opensc.dll

I tried using swig and failed. I also tried various h2xs tutorials and i still don't get anywhere. I can't use Inline::C because the target systems don't have compilers or a full Perl suite installed (using perlapp instead).

I'm not sure what else to try (or where i failed). I'm completly baffled by that perl-xs-c stuff.

Could you give me a step-by-step walkthrough on how to get this to work? All at once would be nice, but i'm perfectly happy with "try this next and then see how far you get".

Thanks in advance.

Edit: I'm definitely going in the right direction. If this works (there are still a few question marks), i feel a meditation with step-by-step instructions comming up....

Don't use '#ff0000':
use Acme::AutoColor; my $redcolor = RED();
All colors subject to change without notice.

In reply to h2xs on Windows by cavac

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.