ChatGPT - How Long Till They Realize I’m a Robot?

Image
I tried it first on December 2nd... ...and slowly the meaning of it started to sink in. It's January 1st and as the new year begins, my future has never felt so hazy. It helps me write code. At my new company I'm writing golang, which is new for me, and one day on a whim I think "hmmm maybe ChatGPT will give me some ideas about the library I need to use." Lo-and-behold it knew the library. It wrote example code. It explained each section in just enough detail. I'm excited....It assists my users. I got a question about Dockerfiles in my teams oncall channel. "Hmmm I don't know the answer to this either"....ChatGPT did. It knew the commands to run. It knew details of how it worked. It explained it better and faster than I could have. Now I'm nervous....It writes my code for me. Now I'm hearing how great Github Copilot is - and it's built by OpenAI too...ok I guess I should give it a shot. I install it, and within minutes it'

Connecting to an API written in C from C#

The last couple of days have been trying for me at work.

Fortunately, I learned something. I was working on an application that needed to connect to a 3rd party API that was originally written in C - like a billion years ago. There was good documentation on the software, but in order to connect to it in C#, I had to go online and find out how from somewhere else. So here's what you do:

First, make sure the API was installed on your system, so that the dll's are registered in the GAC.

Second, start a new project in C#, and create a new class. Make sure to import "System.Runtime.InteropServices". At the top of the class definition, do something like this:

[DllImport("User32.dll")]
public static extern int MessageBox(int h, string m, string c, int type);

Now, you'll have to know the signature of the methods you want to use from the API first. Anyway, once you declare that the function you want to use is defined externally, and you've told the compiler where it's defined, you can start using the function:

MessageBox(0,"API Message Box","API Demo",0);

This is great stuff to know. You might think that you could just reference the dll in the Solution Explorer in Visual Studio, but if it's not a valid .NET dll, it won't let you do so.

The tutorial I used to figure this stuff out is located here.

One more thing that might be useful to you is passing pointers to variables, especially if you're calling C functions. to do so, just declare the function with the keyword "ref" right before the parameter, like so:

[DllImport("Blah32.dll")]
public static extern int blahmethod(ref char[] someVariable, int otherVariable);

And then use ref again when calling the function:

var x = blahmethod(charArray1, someInt);

Comments

Popular posts from this blog

ChatGPT - How Long Till They Realize I’m a Robot?

Architectural Characteristics - Transcending Requirements

My experience with Udacity